gpt4 book ai didi

redirect - Nginx 从不存在的子域重定向

转载 作者:太空宇宙 更新时间:2023-11-03 14:47:02 25 4
gpt4 key购买 nike

我有 https://example.com

还有https://admin.example.com

https://forum.example.com

当请求 example.com 或 admin.example.com 或 forum.example.com 时,nginx 重定向到 SSL 连接(https://example.com 等)

example.com.conf :

server {
charset utf-8;
client_max_body_size 128M;

listen 443 ssl;

server_name example.com www.example.com;
root /var/www/example.com/...;
index index.php;

ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_dhparam /etc/ssl/certs/dhparam.pem;
ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AE$
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_stapling on;
ssl_stapling_verify on;
add_header Strict-Transport-Security max-age=15768000;

access_log /var/log/nginx/example.com-access.log;
error_log /var/log/nginx/example.com-error.log;

location / {
# Redirect everything that isn't a real file to index.php
try_files $uri $uri/ /index.php$is_args$args;
}

location ~* \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
try_files $uri =404;
access_log off;
expires 7d;
}
error_page 404 /404.html;

location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

location ~ /\.(ht|svn|git) {
deny all;
}

# let's encrypt (ssl folder)
location ~ /.well-known {
allow all;
}
}

server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
return 301 https://$server_name$request_uri;
}

如果我请求不存在的子域,如 xxx.example.com,它会重定向到 https://example.com通过 default.conf

server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
return 301 https://example.com;
}

但如果我请求 https://xxx.example.com它像 admin.example.com 一样打开,但出现 SSL 插入错误。但我也需要像 xxx.example.com 请求一样重定向它。

如果我附加 default.conf

server {
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
server_name _;
return 301 https://example.com;
}

我收到所有主机的 ERR_CONNECTION_REFUSED。

最佳答案

But if i request https://xxx.example.com it opening like admin.example.com with SSL cert error. But I need to redirect it also like xxx.example.com request.

没办法。重定向需要有效的证书,因为重定向仅在检查证书后发生。如果没有与 URL 匹配的证书,您只会收到证书错误,并且不会到达重定向。

关于redirect - Nginx 从不存在的子域重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38209273/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com