![Nginx,三个相同的 vhost 配置,一个可以正常工作,另外两个重定向次数过多](https://linux22.com/image/779558/Nginx%EF%BC%8C%E4%B8%89%E4%B8%AA%E7%9B%B8%E5%90%8C%E7%9A%84%20vhost%20%E9%85%8D%E7%BD%AE%EF%BC%8C%E4%B8%80%E4%B8%AA%E5%8F%AF%E4%BB%A5%E6%AD%A3%E5%B8%B8%E5%B7%A5%E4%BD%9C%EF%BC%8C%E5%8F%A6%E5%A4%96%E4%B8%A4%E4%B8%AA%E9%87%8D%E5%AE%9A%E5%90%91%E6%AC%A1%E6%95%B0%E8%BF%87%E5%A4%9A.png)
我的服务器上有三个网站。我的主页 gamenotify.net 运行良好。我的其他两个网站在 www 和非 www 网址之间重定向过多。我的 vhost 文件与我的主页相同。我只是复制了它并替换了文件夹名称和网页名称。
我的主页配置文件
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name www.gamenotify.net;
set $base path/nginx/sites;
root $base/gamenotify;
# SSL
ssl_certificate path/gamenotify.net/fullchain.pem;
ssl_certificate_key path/gamenotify.net/privkey.pem;
ssl_trusted_certificate path/gamenotify.net/chain.pem;
# HSTS
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;
# security
include nginxconfig.io/security.conf;
# index.php
index index.php;
# index.php fallback
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# additional config
include nginxconfig.io/general.conf;
include nginxconfig.io/gamenotify.net.wordpress.conf;
# handle .php
location ~ \.php$ {
fastcgi_pass php-fpm;
include nginxconfig.io/php_fastcgi.conf;
}
}
# non-www, subdomains redirect
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name .gamenotify.net;
# SSL
ssl_certificate path/gamenotify.net/fullchain.pem;
ssl_certificate_key path/gamenotify.net/privkey.pem;
ssl_trusted_certificate path/gamenotify.net/chain.pem;
return 301 https://www.gamenotify.net$request_uri;
}
# HTTP redirect
server {
listen 80;
listen [::]:80;
server_name .gamenotify.net;
include nginxconfig.io/letsencrypt.conf;
location / {
return 301 https://www.gamenotify.net$request_uri;
}
}
我的 wordpress 配置只是为了隐藏某些文件和文件夹。
相比之下,我的第二个页面配置文件
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name www.fotobox-mettingen.de;
set $base path/nginx/sites;
root $base/fotobox;
# SSL
ssl_certificate path/fotobox-mettingen.de/fullchain.pem;
ssl_certificate_key path/fotobox-mettingen.de/privkey.pem;
ssl_trusted_certificate path/fotobox-mettingen.de/chain.pem;
# HSTS
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;
# security
include nginxconfig.io/security.conf;
# index.php
index index.php;
# index.php fallback
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# additional config
include nginxconfig.io/general.conf;
include nginxconfig.io/fotobox-mettingen.de.wordpress.conf;
# handle .php
location ~ \.php$ {
fastcgi_pass php-fpm;
include nginxconfig.io/php_fastcgi.conf;
}
}
# non-www, subdomains redirect
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name .fotobox-mettingen.de;
# SSL
ssl_certificate path/fotobox-mettingen.de/fullchain.pem;
ssl_certificate_key path/fotobox-mettingen.de/privkey.pem;
ssl_trusted_certificate path/fotobox-mettingen.de/chain.pem;
return 301 https://www.fotobox-mettingen.de$request_uri;
}
# HTTP redirect
server {
listen 80;
listen [::]:80;
server_name .fotobox-mettingen.de;
include nginxconfig.io/letsencrypt.conf;
location / {
return 301 https://www.fotobox-mettingen.de$request_uri;
}
}
我的第三个页面有相同的配置和相同的错误。只有我的第一个页面运行良好。现在我的第二个配置的错误在哪里?为什么我得到这么多的重定向?
感谢您的帮助
答案1
好的,我找到了问题所在。感谢 Richard。我的问题是 wordpress 配置错误。所以我陷入了无限循环。
必须更改数据库中网站标题和 URL 的一些条目。
谢谢<3