2011-07-07, 04:14 PM | #1 | |
注册日期: 2003-10-22
帖子: 11,052
积分:6
精华:24
现金:14344金币
资产:29325301金币
|
[转]在nginx上对同一域名配置http和https协议
最近有点对nginx情有独钟,所有研究了nginx的各个方面的东西,给大家分享一下在nginx上对同一域名配置http和https协议的方法: 方法一: rewrite的思想。 server { listen 443; server_name love.ulnmp.com ; index index.html index.htm index.php default.html default.htm default.php; root /var/www/wordpress/; include n.conf; ssl on; ssl_certificate /usr/local/nginx/conf/ssl.crt; ssl_certificate_key /usr/local/nginx/conf/ssl.key; location ~ .*\.(php|php5)?$ { fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_index index.php; include fcgi.conf; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 12h; } log_format love.ulnmp.com '$remote_addr - $remote_user [$time_local] $request ' '$status $body_bytes_sent $http_referer ' '$http_user_agent $http_x_forwarded_for'; access_log /home/wwwlogs/love.ulnmp.com.log love.ulnmp.com; } server { listen 80; server_name love.ulnmp.com; rewrite ^/(.*) https://love.ulnmp.com/$1 permanent; } 第二种方法:把http和https看成同等级别的东西来对待。 server { listen 80; listen 443; server_name love.ulnmp.com ; index index.html index.htm index.php default.html default.htm default.php; root /var/www/wordpress/; include n.conf; ssl on; ssl_certificate /usr/local/nginx/conf/ssl.crt; ssl_certificate_key /usr/local/nginx/conf/ssl.key; location ~ .*\.(php|php5)?$ { fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_index index.php; include fcgi.conf; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 12h; } log_format love.ulnmp.com '$remote_addr - $remote_user [$time_local] $request ' '$status $body_bytes_sent $http_referer ' '$http_user_agent $http_x_forwarded_for'; access_log /home/wwwlogs/love.ulnmp.com.log love.ulnmp.com; } |
|
|
||
|