0

Trying to get nginx to proxy my node.js app and use a domain with it. I'm going to have many domains mapped to the server so i'm using separate .conf files for each server block. The issue i'm having right now is that I can only seem to get the default nginx page to show up when i go to the domain. I'll try to explain the current setup as clearly as possible, and if you need any more information please let me know.

nginx.conf changes

I set the root path to where my apps files are, root /var/www; so for example, an app would be deployed to the folder /var/www/example.com.

server block config

I created a new file for the server block /etc/nginx/conf.d/example_com.conf which contains

server { listen 80; listen [::]:80; server_name example.com www.example.com; location /var/www { proxy_pass http://localhost:3103; include /etc/nginx/proxy_params; } } 

please note that going to my http://myip:3103 renders the app as it should and the file /etc/nginx/proxy_params contains

proxy_buffers 16 32k; proxy_buffer_size 64k; proxy_busy_buffers_size 128k; proxy_cache_bypass $http_pragma $http_authorization; proxy_connect_timeout 59s; proxy_hide_header X-Powered-By; proxy_http_version 1.1; proxy_ignore_headers Cache-Control Expires; proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504 http_404; proxy_no_cache $http_pragma $http_authorization; proxy_pass_header Set-Cookie; proxy_read_timeout 600; proxy_redirect off; proxy_send_timeout 600; proxy_temp_file_write_size 64k; proxy_set_header Accept-Encoding ''; proxy_set_header Cookie $http_cookie; proxy_set_header Host $host; proxy_set_header Proxy ''; proxy_set_header Referer $http_referer; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Original-Request $request_uri; 

Is there anything I am doing wrong here? Do you need any more info? Please let me know! nginx is pretty new for me and i feel like i'm super close i'm just note understanding something. Thanks!

1 Answer 1

1

The location directive specifies a client request URI, not a file location on your local file system.

So location /var/www { means use this location when someone requests www.example.com/var/www

Try changing it to location / {

3
  • that was it, thank you! Just my lack of understanding of nginx :D Commented Sep 12, 2018 at 15:25
  • No worries, also you do not need to create config files for each domain if they all basically do the same thing. You can create one and define the server name with a named regex capture and then use that variable, or the $host variable within the rest of your config, like root /var/www/$host; access_log /var/log/nginx/$host.access.log etc etc Commented Sep 12, 2018 at 15:51
  • please note that going to my myip:3103 renders the app as it should you might also want to configure your node server to bind to 127.0.0.1, to prevent anyone else from accessing it directly Commented Sep 12, 2018 at 15:56

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.