Nginx 和 CloudFlare 上两个网站 运行 Node.js 的重定向问题
Redirection issue with two websites running Node.js on Nginx and CloudFlare
我在 sites-available
中有两个文件,机器上每个网站 运行 一个。两者都有相同的代码,只是替换了网站的域名和端口。这两个站点也都链接到 sites-enabled
。
reesmorris.co.uk
(效果很好):
# Remove WWW from HTTP
server {
listen 80;
server_name www.reesmorris.co.uk reesmorris.co.uk;
return 301 https://reesmorris.co.uk$request_uri;
}
# Remove WWW from HTTPS
server {
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/reesmorris.co.uk/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/reesmorris.co.uk/privkey.pem;
server_name www.reesmorris.co.uk;
return 301 https://reesmorris.co.uk$request_uri;
}
# HTTPS request
server {
# Enable HTTP/2
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name reesmorris.co.uk;
ssl_certificate /etc/letsencrypt/live/reesmorris.co.uk/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/reesmorris.co.uk/privkey.pem;
location / {
proxy_pass http://127.0.0.1:3000;
include /etc/nginx/proxy_params;
}
}
francescoiacono.co.uk
(有重定向循环):
# Remove WWW from HTTP
server {
listen 80;
server_name www.francescoiacono.co.uk francescoiacono.co.uk;
return 301 https://francescoiacono.co.uk$request_uri;
}
# Remove WWW from HTTPS
server {
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/francescoiacono.co.uk/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/francescoiacono.co.uk/privkey.pem;
server_name www.francescoiacono.co.uk;
return 301 https://francescoiacono.co.uk$request_uri;
}
# HTTPS request
server {
# Enable HTTP/2
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name francescoiacono.co.uk;
ssl_certificate /etc/letsencrypt/live/francescoiacono.co.uk/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/francescoiacono.co.uk/privkey.pem;
location / {
proxy_pass http://127.0.0.1:4000;
include /etc/nginx/proxy_params;
}
}
为了实验,我将损坏网站的第一个服务器块中的 return
值替换为 403,即使该网站使用 HTTPS,它似乎也会显示。此外,完全删除损坏网站上的第一个服务器块将导致网站完全重定向到已经运行的网站。
两个网站都使用 CloudFlare 进行 DNS 路由。 CloudFlare 在两个网站上都是 'paused',这意味着它只处理路由,其中两个网站到服务器的路由相同,AAAA 和 A 记录相同。
我不太熟悉服务器块,所以如果有人对正在发生的事情有任何想法,我们将不胜感激。
似乎通过在 CloudFlare DNS 中创建两个网站 'paused' 解决了这个问题。这是最初完成的,虽然可能没有足够的时间来传播。
自从这个 post 创建以来,我没有修改过代码,尽管我确保这两个站点都在 CloudFlare 上 'paused'(reesmorris.co.uk
,但是 francescoiacono.co.uk
不是) - 所以这似乎是 CloudFlare 的错误配置问题。
我在 sites-available
中有两个文件,机器上每个网站 运行 一个。两者都有相同的代码,只是替换了网站的域名和端口。这两个站点也都链接到 sites-enabled
。
reesmorris.co.uk
(效果很好):
# Remove WWW from HTTP
server {
listen 80;
server_name www.reesmorris.co.uk reesmorris.co.uk;
return 301 https://reesmorris.co.uk$request_uri;
}
# Remove WWW from HTTPS
server {
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/reesmorris.co.uk/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/reesmorris.co.uk/privkey.pem;
server_name www.reesmorris.co.uk;
return 301 https://reesmorris.co.uk$request_uri;
}
# HTTPS request
server {
# Enable HTTP/2
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name reesmorris.co.uk;
ssl_certificate /etc/letsencrypt/live/reesmorris.co.uk/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/reesmorris.co.uk/privkey.pem;
location / {
proxy_pass http://127.0.0.1:3000;
include /etc/nginx/proxy_params;
}
}
francescoiacono.co.uk
(有重定向循环):
# Remove WWW from HTTP
server {
listen 80;
server_name www.francescoiacono.co.uk francescoiacono.co.uk;
return 301 https://francescoiacono.co.uk$request_uri;
}
# Remove WWW from HTTPS
server {
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/francescoiacono.co.uk/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/francescoiacono.co.uk/privkey.pem;
server_name www.francescoiacono.co.uk;
return 301 https://francescoiacono.co.uk$request_uri;
}
# HTTPS request
server {
# Enable HTTP/2
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name francescoiacono.co.uk;
ssl_certificate /etc/letsencrypt/live/francescoiacono.co.uk/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/francescoiacono.co.uk/privkey.pem;
location / {
proxy_pass http://127.0.0.1:4000;
include /etc/nginx/proxy_params;
}
}
为了实验,我将损坏网站的第一个服务器块中的 return
值替换为 403,即使该网站使用 HTTPS,它似乎也会显示。此外,完全删除损坏网站上的第一个服务器块将导致网站完全重定向到已经运行的网站。
两个网站都使用 CloudFlare 进行 DNS 路由。 CloudFlare 在两个网站上都是 'paused',这意味着它只处理路由,其中两个网站到服务器的路由相同,AAAA 和 A 记录相同。
我不太熟悉服务器块,所以如果有人对正在发生的事情有任何想法,我们将不胜感激。
似乎通过在 CloudFlare DNS 中创建两个网站 'paused' 解决了这个问题。这是最初完成的,虽然可能没有足够的时间来传播。
自从这个 post 创建以来,我没有修改过代码,尽管我确保这两个站点都在 CloudFlare 上 'paused'(reesmorris.co.uk
,但是 francescoiacono.co.uk
不是) - 所以这似乎是 CloudFlare 的错误配置问题。