【发布时间】:2017-03-23 11:30:57
【问题描述】:
我有一个 Ubuntu Node.js 服务器与我的 http://www.example.com 网站一起工作。 我使用 httpx://localhost:3000 进行测试,然后当我将其部署到 Ubuntu 时, 我仍然必须输入端口(www.example.com:3000)。有人告诉我实施 反向代理以删除端口 3000 要求。我安装了 nginx 并添加了 下列的: sudo nano /etc/nginx/sites-available/default ----------删除所有然后复制/粘贴--------------
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://67.205.128.21:3000;
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;
}
}
这行得通,并且取消了输入端口 3000 的要求。 然后我发现我需要使用 SSL/证书运行我的应用程序。 我能够对 nginx 进行更改以使其以https://www.example.com:3000 工作。 但现在我需要摆脱端口 3000 的要求。 我尝试了与 http: 相同的反向代理设置,但没有奏效。 如何配置 nginx 以删除端口 3000 要求。 以下是我在浏览器中输入时当前发生的情况:
http://67.205.128.21 - Works
http://example.com - Redirects to https://example ; Error: Redirects too many times
http://www.example.com - Redirects to https://example ; Error: Redirects too many times
http://example.com:3000 - Works
http://www.example.com:3000 - Works
当前 nginx 配置:
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name example.com www.example.com;
return 301 https://$server_name$request_uri;
location ~ /.well-known {
allow all;
}
# SSL configuration
#
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
include snippets/ssl-example.com.conf;
include snippets/ssl-params.conf;
server_name example.com;
location / {
proxy_pass http://67.205.128.21:3000;
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;
}
}
【问题讨论】: