By soldiercrp
Hi!
I have a big doubt about how to load the content of a folder in the browser without use a domain using nginx in CentOS… I mean, like apache works, for example:
If I have in /var/www/html/page1 and /var/www/html/page2 I can open those folders in the url with this
my_ip/page1 my_ip/page2
So, I want to do the same in my droplet… I have many folders in my www folder and I want to access to these folders like the above.
I want to do this because, I want to provide access to the demos of my apps of my portafolio to the users.
Thanks in advance
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Set an Nginx vhost to the root where your demos are stored, like this:
server {
listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 default ipv6only=on; ## listen for ipv6
root /var/www/html/;
index index.html index.htm index.php;
# Make site accessible from http://localhost/
server_name .domainname-goes-here.com;
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location / {
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't break when using query string
#try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_pass php;
}
}
Then just go to the domain/subdomain you set for it and add the folder name ir example.com/page2/
make sure to have a index file (index.php, html, etc…).
if you want it to be accesible via IP you need to make it your default website/virtual host by changing this line:
server_name .domainname-goes-here.com;
to
server_name _;
but it looks professional to use a domain/subdomain and is easier to remember. make sure you don’t have another virtual host as default one!
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.