简体   繁体   English

Node.js + Nginx设置:无法访问域名

[英]Node.js + Nginx Setup: Could not access domain name

Hi I am encountering the issue same with How to set up nodejs + nginx on windows 8 . 嗨,我遇到了与如何在Windows 8上设置nodejs + nginx相同的问题。 I tried the solution given in this link by adding it in the host file but it is still not working. 我通过将其添加到主机文件中来尝试了此链接中给出的解决方案,但是它仍然无法正常工作。 Can you give me other solution to this problem? 您能给我其他解决方案吗? Thanks. 谢谢。

When I am accessing robstodo.com in the browser, I have this robstodo.com 当我在浏览器中访问robstodo.com时,我拥有了robstodo.com

 #user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; pid logs/nginx.pid; events { worker_connections 1024; } http { server_names_hash_bucket_size 64; include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; upstream app_robstodo { server 127.0.0.1:3000; } server { listen 8080; server_name robstodo.com; access_log \\logs\\minitorials.log; location / { proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-NginX-Proxy true; proxy_pass http://app_robstodo/; proxy_redirect off; } } } 

If that is not a registered domain and you're using a hosts file, then in addition to this: 如果这不是一个注册域,并且您正在使用主机文件,那么除了:

127.0.0.1 robstodo.com

also add this: 还要添加以下内容:

127.0.0.1 www.robstodo.com

because that's what you are using in your screenshot, a www subdomain. 因为这就是您在屏幕截图中使用的www子域。

You need to use exactly the same domain in your hosts file, in the nginx config and in your browser. 您需要在hosts文件,nginx配置和浏览器中使用完全相同的域。 The www.robstodo.com is a completely different domain than robstodo.com as far as the name resolver is concerned. 就名称解析器而言,www.robstodo.com是与robstodo.com完全不同的域。 Also note that you need to have the app_robstodo domain defined as well. 还要注意,您还需要定义app_robstodo域。

Now, I would try to hunt the problems with little steps. 现在,我将尝试一点点解决这些问题。 Can you access the Node app directly using IP address with no proxy? 您可以使用不带代理的IP地址直接访问Node应用程序吗? Can you access it using the app_robstodo domain name with no proxy? 您可以使用没有代理的app_robstodo域名访问它吗? Can you access the nginx proxy with the IP address? 您可以使用IP地址访问Nginx代理吗? And finally can you access the nginx proxy with the domain name? 最后,您可以使用域名访问Nginx代理吗?

Make sure that you use the correct ports on each step. 确保在每个步骤上使用正确的端口

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM