Nginx.conf and Node.js installation script

Today I first installed the NGINX server. It works very well, but I had a small problem with the server configuration for collaboration with node.js.

I want to have the following logic in nginx.conf.

question marks are optional parameters :) Perhaps from 0 to 7 parameters.

I apologize if this installation scenario is very simple, but I have been fighting it for almost 3 hours and I am stuck. Step 1 and 2 are ready - 10x for google.

Relationship Dan

+6
source share
2 answers

You should check this answer . From the following accepted answer, I got something like this:

upstream node_app { server localhost:8080; } server { listen 80; server_name FOO_HOSTNAME_GOES_HERE; root /the/root/to/foo/document/root; access_log /var/log/nginx/foo.access.log; error_page 404 /404.html; location /remote_data/ { # Proxy request to node: 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-NginX-Proxy true; proxy_pass http://node_app; proxy_redirect off; access_log /var/log/nginx/foo_nodeapp.access.log; } location / { try_files $uri $uri/index.html 404; } } 

Unconfirmed.

+5
source

I managed to get it to work with the following conf:

 server { root /var/www; listen 80; server_name _; location ~* /remote_data { # Proxy request to node: 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-NginX-Proxy true; proxy_pass http://node_app; proxy_redirect off; break; } location / { index index.html index.htm; location ~ \.(js|css|png|jpg|jpeg|gif|ico|html|less)$ { expires max; break; } rewrite ^/(.*)?$ /index.html?q=$1 last; } # serve static files directly location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico)$ { access_log off; expires 30d; } } 
+2
source

Source: https://habr.com/ru/post/905867/


All Articles