我正试图根据一个目录为多个主机创建一个单一的Nginx配置。我遵循了一个指南,它似乎很适合标准HTTP设置,但是当我添加HTTPS 301重定向时,可能会出现“无效重定向”错误。对此有什么想法吗?下面是我的配置。发送
server {
listen x.x.x.x:80;
server_name ~^(?.+?).domain.com$;
return 301 https://$server_name$request_uri;
}
server {
listen x.x.x.x:443 ssl default_server;
server_name ~^(?.+?).domain.com$;
root /var/web/$sname;
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
ssl_certificate /etc/letsencrypt/live/wildcard.domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/wildcard.domain.com/privkey.pem;
access_log /var/log/nginx/$sname-access.log;
error_log /var/log/nginx/wildcard-error.log debug;
error_page 404 /index.php;
sendfile off;
location ~ \.php {
include fastcgi.conf;
#fastcgi_index index.php;
include cors_support;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
}
location ~ /\.ht {
deny all;
}
location /.well-known {
root /var/www/html;
}
}
发布于 2021-06-28 03:19:48
您的重定向是“无效的”,因为您试图重定向到https://~^(?.+?).domain.com$
,这显然是无效的。
为何会这样呢?
您选择按以下方式编写重定向:
return 301 https://$server_name$request_uri;
这没道理。server_name
不是有效的主机名。
相反,您应该重定向到用户代理使用的同一台主机。在那里使用的正确变量是$host
,而不是$server_name
。
return 301 https://$host$request_uri;
https://serverfault.com/questions/1068027
复制相似问题