Nginx配置https服务器,http重定向到https
server {
listen 443;
server_name www.zhangfangzhou.cn;
index index.html index.htm index.php default.html default.htm default.php;
root /home/zhangfangzhou.cn;
ssl on;
ssl_certificate /usr/local/nginx/conf/vhost/zhangfangzhou_cn.crt;
ssl_certificate_key /usr/local/nginx/conf/vhost/server.key;
include wordpress.conf;
error_page 404 /404.html;
location ~ [^/]\.php(/|$)
{
# comment try_files $uri =404; to enable pathinfo
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
#include pathinfo.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
access_log /home/wwwlogs/zhangfangzhou.cn.log access;
error_log /home/wwwlogs/zhangfangzhou.cn.error.log error;
location /wp-content/uploads {
location ~ .*\.(php)?$ {
deny all;
}
}
#禁止附件目录运行PHP
#附件目录限制ip访问
location ^~ /wp-content/uploads/ {
deny 42.159.103.191;
}
#给 wp-login.php 添加 htpasswd 验证
location ^~ /wp-login.php {
location ~ [^/]\.php(/|$) {
# comment try_files $uri =404; to enable pathinfo
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
#include pathinfo.conf;
}
auth_basic "Please Input Your PassWord";
auth_basic_user_file /usr/local/nginx/conf/vhost/.htpasswd;
}
}
#重定向zhangfangzhou.cn到https://www.zhangfangzhou.cn
server {
listen 80;
server_name zhangfangzhou.cn;
return 301 https://www.zhangfangzhou.cn$request_uri;
}
#重定向www.zhangfangzhou.cn到https://www.zhangfangzhou.cn
server {
listen 80;
server_name www.zhangfangzhou.cn;
return 301 https://www.zhangfangzhou.cn$request_uri;
}