简体   繁体   中英

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 . 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

 #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.

You need to use exactly the same domain in your hosts file, in the nginx config and in your browser. The www.robstodo.com is a completely different domain than robstodo.com as far as the name resolver is concerned. Also note that you need to have the app_robstodo domain defined as well.

Now, I would try to hunt the problems with little steps. Can you access the Node app directly using IP address with no proxy? Can you access it using the app_robstodo domain name with no proxy? Can you access the nginx proxy with the IP address? And finally can you access the nginx proxy with the domain name?

Make sure that you use the correct ports on each step.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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