Change static file serving nginx from jar?

I am running my jar project in nginx. This is a conf file

server { listen 80; server_name site.in; root /root/site-demo/; access_log /var/log/site/access_log; error_log /var/log/site/error_log; location / { proxy_pass http://127.0.0.1:4000/; proxy_redirect http://127.0.0.1:4000 http://site.in; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } } 

When I tried to put the expires part for static files in conf, this did not work. I read that this could be due to the fact that static files are served by a jar, not nginx. If so, what changes should I make to the above conf file so that the static file can execute nginx for my project.

According to the answer, I changed conf as shown below. Now all static files show error 403.

 server { listen 80; server_name site.in; root /root/site-demo/; access_log /var/log/site/access_log; error_log /var/log/site/error_log; location / { proxy_pass http://127.0.0.1:4000/; proxy_redirect http://127.0.0.1:4000 http://site.in; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } location /static { alias /root/site-demo/static; autoindex on; expires max; } } 
+4
source share
2 answers

Add this to your nginx configuration:

  location /static { alias /path/to/your/static/folder; autoindex on; expires max; } 

EDIT

nginx requires the whole tree to be readable, not just where your root runs in nginx.conf. So the team

 sudo chmod -R 777 /root/site-demo/static 

should solve the problem with permissions. But, I think it’s not good - for security reasons - to place your site in the /root directory of your web server. Usually the site is placed in the /var/www folder.

PS

The chmod -R 777 gives owners, groups, and other users the right to read, write, and execute files in a folder and in all its subfolders.

+2
source

check the nginx configuration here:

 /etc/nginx/sites-enabled/ /etc/nginx/sites-available/ 

I had the same problem that you are describing Noticed that I had several configuration files Leave only one configuration file fixed This site is also useful: https://realpython.com/blog/python/kickstarting-flask-on- ubuntu-setup-and-deployment /

0
source

All Articles