How to access to folder without domain using nginx and CentOS?


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

Show comments

Submit an answer

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!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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/

        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

        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

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:

Make site accessible from http://localhost/



Make site accessible from http://localhost/

    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!