有戏

 找回密码
 立即注册
简历下载
搜索
热搜: 活动 交友 discuz
查看: 441|回复: 0

Nginx重定向配置

[复制链接]

30

主题

30

帖子

8600

积分

论坛元老

Rank: 8Rank: 8

积分
8600
发表于 2017-11-23 11:24:45 | 显示全部楼层 |阅读模式
我们使用自己的Linux中用Nginx实现还是比较靠谱。我们来看看Nginx配置。

Nginx重定向配置
所有非www二级域名都跳转到www.sojson.com下去。
#所有非www.sojson.com开始的域名,都重定向到www.sosjon.com下去。
if ($http_host !~ "^www.sojson.com$") {
        rewrite  ^(.*)    http://www.sojson.com$1 permanent;
}
一级域名跳转到www二级域名下面去。
#只是一级域名“sojson.com” 跳转到www.sojson.com去。
if ($http_host ~ "^sojson.com$") {
        rewrite  ^(.*)    http://www.sojson.com$1 permanent;
}
Nginx config配置位置参考:
server{
        listen          80;
        server_name    www.sojson.com admin.sojson.com sojson.com;
        index index.html;
        access_log      syslog:server=127.0.0.1,facility=local6,tag=nginxlog_access,severity=notice main;
        error_log       syslog:server=127.0.0.1,facility=local6,tag=nginxlog_error;
               
        #我在这里
        if ($http_host ~ "^sojson.com$") {
                rewrite  ^(.*)    http://www.sojson.com$1 permanent;
        }
               
        location ~* ^.+\.(ico|gif|jpg|jpeg|png)$ {
                access_log off;
                expires 7d;
        }
        location ~* \/(sitemap|robots)\.(html|txt|xml|xsl)$ {
                root /data/www/sojson.com/sitemap;
        }
        location / {
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                if ($host ~* www\.sojson\.com) {
                        proxy_pass  http://www.sojson.com:8888;
                }
                if ($host ~* admin\.sojson\.com) {
                        proxy_pass  http://admin.sojson.com:8888;
                }
        }
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|有戏 粤ICP备2020111303号

GMT+8, 2025-12-6 18:22 , Processed in 0.084336 second(s), 19 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

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