娱乐新地带论坛

娱乐新地带论坛 (https://bbs.1819.net/index.php)
-   『软件使用』 (https://bbs.1819.net/forumdisplay.php?f=11)
-   -   Linux [转]在nginx上对同一域名配置http和https协议 (https://bbs.1819.net/showthread.php?t=74081)

Tony 2011-07-07 04:14 PM

[转]在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;
}


所有时间均为北京时间。现在的时间是 12:17 AM

©2003-2024 1819.net All rights reserved. © 2024