I start a node.js server on the aws cloud, the location of the server is /home/ubuntu/home/fablab. I can start my node.js server with nginx in port 80, everything is working fine.
Then I am following the tutorial to work node.js and nginx on the server, I reconfigure the node.js port to 61337, build a fablab.conf under the folder of /etc/nginx/sites-available,
and then ln -s /etc/nginx/sites-available/fablab.conf /etc/nginx/sites-enabled/fablab.conf.
This is my fablab.conf
server {
listen 80;
server_name fablab;
location ~ ^/(images/|img/|javascript/|js/|css/|stylesheets/|flash/|media/|static/|robots.txt|humans.txt|favicon.ico) {
root /home/ubuntu/node/fablab/public;
access_log off;
expires max;
}
client_max_body_size 16M;
root /home/ubuntu/node/fablab;
index /home/ubuntu/node/fablab/public/forum.html;
location / {
access_log off;
proxy_pass http://127.0.0.1:61337;
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;
proxy_set_header Host $http_host;
#proxy_set_header Host $host;
proxy_set_header X-NginX-Proxy true;
# websockets support
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
}
}
I reload and restart the nginx, and when I go to the server IP address and port 80, the page is still nginx's welcome page.
Why it doesn't work so far, everything I missed out? I think the key for the fablab.conf, is the proxy_pass http://127.0.0.1:61337
, is it already?
I have two confusions
-
do I have to use the default.conf in the /etc/nginx/sites-enabled, some other names are ok?
-
in the conf file, server_name is supposed to be host name, what if I only have IP address, not host name right now, how to do in this host name. as it is on AWS, do i need to fill in this as the my aws serer's domain name like ec2-24-210-148-112.us-west-2.compute.amazonaws.com
-
in the tutorial, server_name in the conf file is saying like this :
Make sure to set the A Record on your domain's DNS settings to your server's IP address.
You can test if was set properly by using the
dig
command: dig yourdomain.com
what does it mean ? how would I do it
Best Answer
Your configuration seems to be using Virtual Hosting; in other words, nginx decides "which"
server{..}
block matches a request based on the host the request specifies. If the hostname specified doesn't correspond to any server_name, you'll end up with the default catch all site.Your host name isn't a valid DNS name, but have no fear - put fablab in
/etc/hosts
(winderz puts it in Windows\System 32\drivers\etc ) something like this (specify your webserver's IP ) :which should allow your host to resolve fablab to that Ip, and then NGINX should be able to route your request to the proper server.
Hope it Helps!