全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
查看: 7515|回复: 12

[nginx] Nginx下强制http://跳转https://配置

[复制链接]
发表于 2010-10-11 19:29:13 | 显示全部楼层 |阅读模式
看到坛里有人求这个,正好今天把LNMP重装了,发上来赚点分。

我自己使用的配置如下,www目录、证书目录等请根据自己实际情况修改。
/usr/local/nginx/conf/vhost/hostloc.com.conf
  1. server {
  2. listen 443;
  3. server_name hostloc.com www.hostloc.com;
  4. index index.html index.htm index.php default.html default.htm default.php;
  5. root  /home/www/hostloc.com;

  6. ssl on;
  7. ssl_certificate  /home/www/key/hostloc.crt;
  8. ssl_certificate_key  /home/www/key/hostloc.key;
  9.        
  10. log_format  hostloc.com '$remote_addr - $remote_user [$time_local] $request ' '$status $body_bytes_sent $http_referer ' '$http_user_agent $http_x_forwarded_for';

  11. access_log  /home/wwwlogs/hostloc.com.log  hostloc.com;

  12. }

  13. server {
  14. listen 80;
  15. server_name hostloc.com www.hostloc.com;
  16. rewrite ^/(.*) https://www.hostloc.com/$1 permanent;
  17. }
复制代码

[ 本帖最后由 yang 于 2010-10-11 19:31 编辑 ]

评分

参与人数 4威望 +55 收起 理由
zyypp + 15 我很赞同
zrdlrofmine + 15 原创内容
newers + 5
cnx + 20 精品文章

查看全部评分

发表于 2010-10-11 19:33:56 | 显示全部楼层
恩,单独增加个server段。
发表于 2010-10-11 19:34:59 | 显示全部楼层
没用难搞死,不知道楼主说的是否有效。
话说,楼主测试通过没有?

评分

参与人数 1威望 +10 收起 理由
小夜 + 10 精品文章

查看全部评分

发表于 2010-10-11 19:35:01 | 显示全部楼层
支持一下,虽然我用不上。
 楼主| 发表于 2010-10-11 19:38:10 | 显示全部楼层
原帖由 cnx 于 2010-10-11 19:34 发表
没用难搞死,不知道楼主说的是否有效。
话说,楼主测试通过没有?


我自己就是用这配置,完全没问题,你试看就懂了。
发表于 2010-10-11 19:39:37 | 显示全部楼层

回复 5# 的帖子

能用就加分了。
发表于 2010-10-11 19:39:40 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2010-10-11 19:40:11 | 显示全部楼层
这个还是不错的。
发表于 2010-10-11 19:48:20 | 显示全部楼层
加分
发表于 2010-10-11 19:49:56 | 显示全部楼层
看来还是发主题贴好呀
我已经在那贴回复了,都没人加分哇
http://www.hostloc.com/redirect. ... 3169&ptid=31223
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2024-5-15 22:40 , Processed in 0.068557 second(s), 9 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表