@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.
Sorry I cannot seem to edit my original question and the questions is actually incompleted..I am trying to put the actual situation here:
This is the current setting in my nginx:
So now when I type example.com I will be redirected to https://example.com thus accessing my web app listening to port 8000.
But I also uploaded my static web in the path `
/home/ftp/single/
I would like to make it accessible via example.com/home/ftp/single/.
So I added a server block:
However, if I type example.com/single/ I would be redirected to https://example.com/single/ and I cannot access the static web.
If I commented out the setting
my static web example.con/single/ will become accessible but my web app is not accessible via example.con anymore. As the https redirection is invalid.
what is the best way to make example.com for webapp and example.com/single for static web both working?
this is my current setting :