我正在尝试拥有一个顶级域名www.example.com这是一个 wordpress 网站,我希望它始终强制使用 HTTPS,但我也有一个子域名subdomain.mysite.com我希望它仅为 HTTP。
现在,我的服务器已经设置好了,subdomain.mysite.com不断重定向到HTTPS在 Firefox 和 Chrome 中,我遇到了太多重定向崩溃。
我的文件有什么问题?
这是我的服务器块文件:
# Default server configuration
#
server {
listen 80;
listen [::]:80;
server_name example.com;
return 301 https://example.com$request_uri;
}
server {
listen 80;
listen [::]:80;
server_name www.example.com;
return 301 https://www.example.com$request_uri;
}
server {
# SSL configuration
#
listen 443 ssl http2;
listen [::]:443 ssl http2;
add_header Strict-Transport-Security "max-age=0;";
root /var/www/example.com/html;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name example.com www.example.com;
include snippets/ssl-example.com.conf;
include snippets/ssl-params.conf;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
# try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ /.well-known {
allow all;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
# www.subdomain.example.com
server {
listen 80;
server_name www.subdomain.example.com;
return 301 http://subdomain.example.com$request_uri;
}
server {
listen 443 ssl http2;
server_name www.subdomain.example.com;
return 301 http://subdomain.example.com$request_uri;
}
server {
# SSL configuration
#
listen 443 ssl http2;
server_name subdomain.example.com;
return 301 http://subdomain.example.com$request_uri;
}
# subdomain.example.com
server {
listen 80;
server_name subdomain.example.com;
root /var/www/subdomain.example.com/html;
index index.php index.html index.htm;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
add_header Strict-Transport-Security "max-age=0;";
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
# try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ /.well-known {
allow all;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
编辑:这些是我尝试访问 subdomain.example.com 时收到的标头
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8,fr;q=0.6,de;q=0.4
Cache-Control:max-age=0
Connection:keep-alive
Cookie:lang=en
Host:subdomain.example.com
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36