Nginx配置https服务器,http重定向到https server { listen 443; server_name www.it.net.cn; index index.html index.htm index.php default.html default.htm default.php; root /home/it.net.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/it.net.cn.log access; error_log /home/wwwlogs/it.net.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; } } #重定向it.net.cn到https://www.it.net.cn server { listen 80; server_name it.net.cn; return 301 https://www.it.net.cn$request_uri; } #重定向www.it.net.cn到https://www.it.net.cn server { listen 80; server_name www.it.net.cn; return 301 https://www.it.net.cn$request_uri; } 可能出现"网页生成了过多的重定向"而无法打开网站,解决办法:调换下面两个server的位置。 (责任编辑:IT) |