node.js - Use nginx to configure the node program. The conf configuration has been changed, but the domain name cannot be accessed?
phpcn_u1582
phpcn_u1582 2017-06-30 09:57:06
0
3
864

I used pm2 to run a node sample program (express sample program). It can currently be opened with http://127.0.0.1:3000. Now I want to open it with my own custom domain name, but I use nginx configuration After that, it still cannot be opened with a custom domain name (http://mydomain.com). It is ok to use 127.0.0.1 or localhost. Do I need to configure the host on this machine? However, after searching around the Internet for nginx configuration experience or instructions, none of them said that I still need to change the host. I hope someone can answer it.

Attach the configuration information of nginx.conf

#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 { 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 nodejs { server 127.0.0.1:3000; } server { listen 80; server_name www.mydomain.com mydomain.com; #charset koi8-r; #access_log logs/host.access.log main; location / { 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_set_header Connection ""; proxy_pass http://nodejs; #root html; #index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } include servers/*; }
phpcn_u1582
phpcn_u1582

reply all (3)
Ty80

Some key points recorded in NodeJs project - QueenKing - SegmentFault /a/11...

    为情所困

    The local environment needs to configure host, and the custom domain name is mapped to 127.0.0.1

      巴扎黑

      The domain name is for external network servers. Why are you accessing the domain name locally?

        Latest Downloads
        More>
        Web Effects
        Website Source Code
        Website Materials
        Front End Template
        About us Disclaimer Sitemap
        php.cn:Public welfare online PHP training,Help PHP learners grow quickly!