gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 23:13:23 24 4
gpt4 key购买 nike

我正在尝试使用 nginx (v1.5.11) 为我的 Node 项目设置域,我已成功将域重定向到网络,但我需要使用 3000 端口,所以现在,我的网络位置看起来像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;
}

}

}

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

谢谢大家

最佳答案

将此添加到您的 server block :

port_in_redirect off;

例如

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

Documentation reference .

您还应该将 server_name 更改为 myNameserver_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;
}
}
}

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

关于node.js - 无法使用 nginx 隐藏位置的端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22194406/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com