我在 Laravel Forge (Nginx) 设置上运行服务器。我正在创建一个网站构建器,用户可以username.sitebuilder.com
(不是我的真实域)www.whatever.com
在其上进行映射,一切运行正常。
但是,我需要为 *.sitebuilder.com 添加 SSL 通配符证书,并且该证书对所有 *.sitebuilder.com 流量均有效。但我需要服务器仍然监听 www.whatever.com(不是 SSL),而添加证书后,该证书不再有效。
如何设置 Nginx 来路由到:
- *.sitebuilder.com -> SSL
- www.whatever.com -> HTTP
当我访问 www.whatever.com 时,我看到的是该Welcome to nginx!
页面,而不是预期的网站。
这是我的配置文件:
# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/sitebuilder.com/before/*;
server {
listen 80;
listen [::]:80;
server_name ~.;
#add_header X-Frame-Options "SAMEORIGIN";
#add_header X-XSS-Protection "1; mode=block";
#add_header X-Content-Type-Options "nosniff";
index index.html index.htm index.php;
charset utf-8;
# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/sitebuilder.com/server/*;
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; }
access_log off;
error_log /var/log/nginx/sitebuilder.com-error.log error;
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name .sitebuilder.com;
root /home/forge/sitebuilder.com/public;
# FORGE SSL (DO NOT REMOVE!)
ssl_certificate /etc/nginx/ssl/sitebuilder.com/00000/server.crt;
ssl_certificate_key /etc/nginx/ssl/sitebuilder.com/00000/server.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers '**PRIVATE KEY**';
ssl_prefer_server_ciphers on;
ssl_dhparam /etc/nginx/dhparams.pem;
#add_header X-Frame-Options "SAMEORIGIN";
#add_header X-XSS-Protection "1; mode=block";
#add_header X-Content-Type-Options "nosniff";
index index.html index.htm index.php;
charset utf-8;
# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/sitebuilder.com/server/*;
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; }
access_log off;
error_log /var/log/nginx/sitebuilder.com-error.log error;
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/sitebuilder.com/after/*;
答案1
您需要指定一个以有效匹配任何server_name
内容,并且我假设 sitebuilder 实际上处理主机名响应。whatever.com
~.