Nginx HTTP和反向代理服务器端口:80和443对node.js不起作用

时间:2020-10-14 15:03:16

标签: php node.js nginx centos

我在centos操作系统上运行Node.js和PHP网站,我的PHP网站在端口80和443上运行良好, 我的Node.js网站在http://example.com:3000下运行良好。

为使反向代理运行http://example.com之类的node.js网站,我在使用NGINX时遇到了以下错误。


nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)  Drop-In: /etc/systemd/system/nginx.service.d
           └─override.conf   Active: failed (Result: exit-code) since Wed 2020-10-14 07:26:44 MST; 14s ago
  Process: 16475 ExecStartPost=/bin/sleep 0.1 (code=exited, status=0/SUCCESS)  Process: 24791 ExecStart=/usr/sbin/nginx (code=exited, status=1/FAILURE)
  Process: 24788 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 24787 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 16474 (code=exited, status=0/SUCCESS)

Oct 14 07:26:43 ip-208-109-15-74.ip.secureserver.net nginx[24791]: nginx: [emerg] bind() to [::]:443 failed (98: Address already in use)
Oct 14 07:26:43 ip-208-109-15-74.ip.secureserver.net nginx[24791]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Oct 14 07:26:43 ip-208-109-15-74.ip.secureserver.net nginx[24791]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Oct 14 07:26:43 ip-208-109-15-74.ip.secureserver.net nginx[24791]: nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
Oct 14 07:26:43 ip-208-109-15-74.ip.secureserver.net nginx[24791]: nginx: [emerg] bind() to [::]:443 failed (98: Address already in use)
Oct 14 07:26:44 ip-208-109-15-74.ip.secureserver.net nginx[24791]: nginx: [emerg] still could not bind()
Oct 14 07:26:44 ip-208-109-15-74.ip.secureserver.net systemd[1]: nginx.service: control process exited, code=exited status=1
Oct 14 07:26:44 ip-208-109-15-74.ip.secureserver.net systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
Oct 14 07:26:44 ip-208-109-15-74.ip.secureserver.net systemd[1]: Unit nginx.service entered failed state.
Oct 14 07:26:44 ip-208-109-15-74.ip.secureserver.net systemd[1]: nginx.service failed.

我尝试使用其他端口:NGINX的8080和8443,但它们不起作用。 当我在PHP上使用ports:8080和8443而在NGINX上使用Prots:80和443时, 然后NGINX可以正常工作,PHP站点无法正常工作。

 #start code

 server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  howtags.com www.howtags.com;
        #root         /usr/share/nginx/html;

        root         /home/howtags/www/node/index.js;
        index index.js;

        set_real_ip_from  192.168.1.0/24;
        real_ip_header     X-Forwarded-For;
        real_ip_recursive on;

        proxy_redirect      off;
        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;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
            proxy_pass http://howtags.com:3200/;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
        }


        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }


# Settings for a TLS enabled server.

    server {
        listen        443 ssl http2 default_server;
        listen       [::]:443 ssl http2 default_server;
        server_name   howtags.com www.howtags.com;
        
        #root          /usr/share/nginx/html;
        root         /home/howtags/www/node/index.js;
        index index.js;

        set_real_ip_from  192.168.1.0/24;
        real_ip_header     X-Forwarded-For;
        real_ip_recursive on;

        proxy_redirect      off;
        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;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;
        
        ssl_certificate "/etc/nginx/conf.d/howtags.com.crt.pem";
        ssl_certificate_key "/etc/nginx/conf.d/howtags.com.key.pem";
        
        ssl_session_cache     shared:SSL:1m;
        ssl_session_timeout   10m;
        ssl_protocols         TLSV1.1 TLSV1.2 TLSV1.3;
        
        #ssl_ciphers   PROFILE=SYSTEM;
        ssl_ciphers    HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers   on;
        
        location / {
        proxy_pass https://howtags.com:3400/;
        proxy_ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;

        proxy_ssl_ciphers              HIGH:!aNULL:!MD5;
        proxy_ssl_trusted_certificate  /etc/nginx/conf.d/howtags.com.crt.pem;
        proxy_ssl_server_name on;
        proxy_ssl_verify        on;
        proxy_ssl_verify_depth  2;
        proxy_ssl_session_reuse on;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }


#Code Ended Here ........

如果有人知道如何在不打扰其他PHP网站的情况下为Node.js运行NGINX反向代理,请帮助我。

0 个答案:

没有答案