微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

node.js – 无法使用nginx隐藏位置的端口

我正在尝试使用Nginx(v1.5.11)为我的节点项目设置一个域,我已成功将域重定向到Web,但我需要使用3000端口,所以现在,我的web位置看起来像http:/ /www.myweb.com:3000/当然,我想只保留“www.myweb.com”这样的部分:http://www.myweb.com/

我有搜索和尝试很多配置,但似乎没有人为我工作,我不知道为什么,这是我的本地Nginx.conf文件,我想将http:// localhost:8000 / text更改为http:// myName /文本,请记住重定向正在工作,我只想“隐藏”该位置上的端口.

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


      server {
        listen       8000;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass http://localhost:8000/;
            proxy_redirect http://localhost:8000/ http://myName/;

        }

        #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;
        }

    }

}

PD.我正在尝试在我的本地Windows 8机器上修复它,但是如果需要其他操作系统,我的远程服务器可以在Ubuntu 12.04 LTS上运行

谢谢大家.

解决方法:

将其添加到您的服务器块:

port_in_redirect off;

例如.

server {
    listen       80;
    server_name  localhost;
    port_in_redirect off;
}

Documentation reference.

您还应该将server_name更改为myName. server_name应该是您的域名.

您还应该在端口80上侦听,然后使用proxy_pass重定向到正在侦听端口8000的任何内容.

完成的结果应如下所示:

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include            mime.types;
    default_type       application/octet-stream;
    sendfile           on;
    keepalive_timeout  65;


    server {
      listen       80;
      server_name  www.myweb.com;

      location / {
        proxy_pass http://localhost:8000/;
      }

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

为清楚起见,删除评论.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐