无法使用 nginx 隐藏位置的端口

Bal*_*ung 7 redirect location nginx node.js

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

我搜索并尝试了很多配置,但似乎没有人为我工作,我不知道为什么,这是我本地的 nginx.conf 文件,我想将http://localhost:8000/文本更改为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;
        }

    }

}
Run Code Online (Sandbox Code Playgroud)

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

谢谢大家。

Bra*_*ldt 7

将此添加到您的server块中:

port_in_redirect off;
Run Code Online (Sandbox Code Playgroud)

例如

server {
    listen       80;
    server_name  localhost;
    port_in_redirect off;
}
Run Code Online (Sandbox Code Playgroud)

文档参考

您还应该将 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;
      }
    }
}
Run Code Online (Sandbox Code Playgroud)

为清楚起见,删除了评论。