我有一个保护*的通配符证书。实例com和我需要删除所有子域请求的规范www,例如:www.subdomain1。实例com=>子域1。实例com公司
我复习了这个问题:https://stackoverflow.com/questions/11323735/nginx-remove-www-and-respond-to-both
但他们建议的第一个服务器块是:
server {
server_name www.example.com;
return 301 $scheme://example.com$request_uri;
}
不适用于www.subdomain。实例com公司如何捕获并返回www*的方案。实例com?
我复习了另一个问题:https://serverfault.com/questions/249952/wildcard-vhosts-on-nginx其中他们使用正则表达式来匹配服务器名称,但我不确定如何将其应用于我的情况。
以下是我当前的设置:
server {
listen [::]:80 ipv6only=off;
server_name example.com *.example.com;
return 301 https://$host$request_uri;
}
server {
# SSL configuration
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
include snippets/ssl-example.com.conf;
include snippets/ssl-params.conf;
server_name example.com *.example.com;
root /usr/share/nginx/webroot;
index index.php index.html index.htm;
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
#subdomain multi site with wp in \'wp\' subdir
if (!-e $request_filename) {
# Redirect wp-* files/folders
rewrite ^(/[^/]+)?(/wp-.*) /wp/$2 last;
# Redirect other php files
rewrite ^(/[^/]+)?(/.*\\.php) /wp/$2 last;
}
...(etc)
}