我有一个Nginx,配置为一个Wordpress子域多站点,主域为domain.com。
我们使用它为我们的客户创建几个站点,然后他们中的一些人想要一个个性化的url,在我们的站点中我们有customername.domain.com和配置Wordpress站点,让customerdomain.com可以在不使用我们的子域的情况下为客户站点服务。
我的Nginx看起来:
map $http_host $blogid {
default -999;
#Ref: http://wordpress.org/extend/plugins/nginx-helper/
#include /var/www/wordpress/wp-content/plugins/nginx-helper/map.conf ;
}
server {
server_name domain.com *.domain.com ;
root /var/www/html/portal;
index index.php;
access_log /var/log/nginx/nginxwp.access.log combined;
error_log /var/log/nginx/nginxwp.error.log;
client_max_body_size 100M;
location / {
try_files $uri $uri/ /index.php?$args ;
}
#WPMU Files
location ~ \.php$ {
autoindex on;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
# With php5-fpm:
#fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
client_max_body_size 100M;
proxy_connect_timeout 180;
proxy_send_timeout 180;
proxy_read_timeout 180;
}
location ~ ^/files/(.*)$ {
try_files /wp-content/blogs.dir/$blogid/$uri /wp-includes/ms-files.php?file=$1 ;
access_log off; log_not_found off; expires max;
}
}在此之前,一切都很顺利。
现在我需要保护我的客户域名。
我如何在ssl证书下将我的客户站点服务到域customerdomain.com,并将其他站点保存在HTTP下,甚至我们的主站点domain.com保持不变?
发布于 2018-04-06 16:45:25
经过大量的研究、尝试和失败,我可以让它以最简单的方式工作。
不要忘记将SAN证书用于您可能希望保护的域。
我刚把Wordpress Multisite作为一个普通网站处理。并确保它的安全为任何其他单一的网站(可湿性粉剂与否)。
至少以我对Nginx的一点点了解,我保护我的站点重定向到ssl侦听器站点(443)。
我没有对每个站点进行单一配置,而是保留了对非SSL站点的实际配置(大部分在我的网络中),然后使用插件Really Simple 强制仅强制我想要保护的站点。其他人将继续“原样”工作。
必须指出,此配置适用于multisite子域。
对于ssl,我刚刚在443端口中创建了一个侦听器,并且我正在进行完全相同的处理,以重定向到正确的blog id。只保留一个服务器块,不管我将来想要保护多少个站点。
我有我的sites-available & sites-enabled目录3文件。
certs.conf
domain.com.conf
ssl_domain.com.conf证书档案:
ssl_certificate /customers/certificates/sancert.pem;
ssl_certificate_key /customers/certificates/sancert.key;domain.com.conf
map $http_host $blogid {
default -999;
#Ref: http://wordpress.org/extend/plugins/nginx-helper/
#include /var/www/wordpress/wp-content/plugins/nginx-helper/map.conf ;
}
server {
server_name domain.com *.domain.com ;
root /var/www/html/portal;
index index.php;
access_log /var/log/nginx/nginxwp.access.log combined;
error_log /var/log/nginx/nginxwp.error.log;
location / {
try_files $uri $uri/ /index.php?$args ;
}
#WPMU Files
location ~ \.php$ {
autoindex on;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
# With php5-fpm:
#fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
client_max_body_size 100M;
proxy_connect_timeout 180;
proxy_send_timeout 180;
proxy_read_timeout 180;
}
location ~ ^/files/(.*)$ {
try_files /wp-content/blogs.dir/$blogid/$uri /wp-includes/ms-files.php?file=$1 ;
access_log off; log_not_found off; expires max;
}
}ssl_domain.com.conf
server {
listen 443;
ssl on;
port_in_redirect off;
server_name domain.com *.domain.com ;
root /var/www/html/portal;
index index.php;
access_log /var/log/nginx/nginxwp.access.log combined;
error_log /var/log/nginx/nginxwp.error.log;
location / {
try_files $uri $uri/ /index.php?$args ;
}
#WPMU Files
location ~ \.php$ {
autoindex on;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
# With php5-fpm:
#fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
client_max_body_size 100M;
proxy_connect_timeout 180;
proxy_send_timeout 180;
proxy_read_timeout 180;
}
location ~ ^/files/(.*)$ {
try_files /wp-content/blogs.dir/$blogid/$uri /wp-includes/ms-files.php?file=$1 ;
access_log off; log_not_found off; expires max;
}
#WPMU x-sendfile to avoid php readfile()
location ^~ /blogs.dir {
internal;
alias /home/portal/wp-content/blogs.dir;
access_log off; log_not_found off; expires max;
}
#add some rules for static content expiry-headers here
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload";
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
} 在我的wordpress中,我已经将该站点的自定义域设置为customerdomain.com,并使用插件Really简单SSL强制HTTPS。
每件事都很有魅力,在SSLabs上有品位的SSLabs。
希望它能为下一个研究解决方案节省时间。
https://serverfault.com/questions/906226
复制相似问题