我在aws云上启动了一个node.js服务器,服务器的位置是/ home / ubuntu / home / fablab。 我可以用端口80的nginx启动我的node.js服务器,一切工作正常。
然后我按照教程来在服务器上工作node.js和nginx,我将node.js端口重新configuration为61337,在/ etc / nginx / sites-available文件夹下build立一个fablab.conf,然后ln -s /etc/nginx/sites-available/fablab.conf /etc/nginx/sites-enabled/fablab.conf。 这是我的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; } }
我重新加载并重新启动nginx,当我去到服务器的IP地址和端口80,该页面仍然是nginx的欢迎页面。
为什么它不工作到目前为止,我错过了什么? 我认为fablab.conf的关键是proxy_pass http://127.0.0.1:61337 ,是不是已经?
我有两个困惑
我必须使用/ etc / nginx / sites-enabled中的default.conf,其他名称还可以吗?
在conf文件中,server_name应该是主机名,如果我现在只有IP地址,而不是主机名,该怎么办。 因为它是在AWS上,我需要填写这个作为我aws serer的域名,如ec2-24-210-148-112.us-west-2.compute.amazonaws.com
在教程中 ,conf文件中的server_name是这样说的:
dig命令testing是否正确设置:dig yourdomain.com 这是什么意思 ? 我将如何做到这一点
您的configuration似乎使用虚拟主机; 换句话说,nginx根据请求指定的主机决定“哪个” server{..}块匹配请求。 如果指定的主机名不对应于任何server_name,则最终将以默认捕获所有站点。
你的主机名不是一个有效的DNS名称,但没有恐惧 – 把fablab放在/etc/hosts (winderz把它放在Windows \ System 32 \ drivers \ etc中)像这样(指定你的web服务器的IP):
192.168.100.17 fablab
这应该允许你的主机将fablabparsing到该IP,然后NGINX应该能够将你的请求路由到正确的服务器。
希望能帮助到你!