Question

how to make example.com for webapp while example.com/single for static web

I have followed this tutorial to setup the nginx as a reverse server Example link

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.

@frostless

Looks like they all came through at once :-). There are preventative measures on the community in an attempt to deter spam, though sometimes various things seem to trigger it, so if you don’t see your post immediately, allow it a few minutes. It could be due to a filter or due to the cache not being up to date.

As for the configuration, even with the SSL configuration, you’d simply add:

    location /static {
        root /path/to/static/files;
    }

to your second sever block, below the first location block. You’d simply modify the path to match where your static files are located.

I dont know why my comments keep being rejected

But actually my current setting is like this, followed by the guide:

server {
        listen 80;
        listen [::]:80 default_server ipv6only=on;
        return 301 https://$host$request_uri;
}
server {
        listen 443;
        server_name your_domain_name;

        ssl on;
        # Use certificate and key provided by Let's Encrypt:
        ssl_certificate /etc/letsencrypt/live/your_domain_name/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/your_domain_name/privkey.pem;
        ssl_session_timeout 5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';

        # Pass requests for / to localhost:8080:
        location / {
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-NginX-Proxy true;
                proxy_pass http://localhost:8080/;
                proxy_ssl_session_reuse off;
                proxy_set_header Host $http_host;
                proxy_cache_bypass $http_upgrade;
                proxy_redirect off;
        }
}

@frostless

You can add additional location blocks to your main server block and set explicit paths.

For example, if we use the server block that was provided in that guide:

server {
    listen 80;

    server_name example.com;

    location / {
        proxy_pass http://localhost:8080;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

We can add a new location block below the first. For the purpose of this example, I’ll use /static.

server {
    listen 80;

    server_name example.com;

    location / {
        proxy_pass http://localhost:8080;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

    location /static {
        root /path/to/static/files;
    }
}

In the above, we’re telling NGINX to pass requests for ./static/..... to the /static location block, which defines a root directory – this would be the full path to where the static files are location.

So if your static files were located in, for example, /home/username/htdocs/static, that’s the path you would use.

You’ll need to reload or restart NGINX after changes are made to configuration.