我有https://example.comNginx的非現有子域
重定向也有https://admin.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它經由default.conf
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
return 301 https://example.com;
}
重定向到https://example.com但是,如果我請求https://xxx.example.com它打開像admin.example.com與SSL SERT錯誤。但我需要重定向它也像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我的所有主機。
清除default.conf中的default_server並將其添加到example.com.conf。是的,當請求'https://xxx.example.com'時,我有sert錯誤,但在重定向到'https://example.com'後,我想要。謝謝你們! – ZeiZ