nginx 配置二级域名跳转以及www 跳转(去除www 跳转),nginx 端口跳转,nginx 保留IP信息

来源:互联网 发布:淘宝主宝贝图片尺寸 编辑:程序博客网 时间:2024/05/16 18:22
server{    listen 80;    sever_name www.so.com *.so.com so.com;    location / {        proxy_set_header Host $host;        if( $uri ~* "/news"){rewrite ^/news(.*)$ http://new.so.com/$2 last;}        if( $host !~* "^www.so.com|^www.so.com\/\w*|^news.so.com|^news.so.com\/\w*"){rewrite ^/ http://www.so.com$uri last;}        proxy_set_header X-Real-IP $remote_addr;        proxy_pass http://127.0.0.1:8080;    }}

第二行 为监听端口80

第三行 为过滤域名,这里为只是so.com 相关域名的配置

第五行 为定义host 域名参数

第六行 为如果访问类似 www.so.com/news/....的链接,自动跳转到 news.so.com/.... 的链接

第七行 为如果域名不是 www.so.com/...或者news.so.com,则自动跳转到www.so.com/... 的链接

第七行 把IP 重定义了一下,这样可以访问X-Real-IP 参数来获得客户端真实的IP(一般访问到的都是nginx 的IP)

第八行 端口跳转

原创粉丝点击