美文网首页
nginx的proxy_pass配置问题

nginx的proxy_pass配置问题

作者: 匆匆岁月 | 来源:发表于2021-10-04 15:29 被阅读0次

proxy_pass配置


location匹配规则

rewrite 重定向

rewrite 企业应用场景

Nginx的rewrite功能在企业里应用非常广泛:

  • 可以调整用户浏览的URL,看起来更规范,合乎开发及产品人员的需求。
  • 为了让搜索引擎搜录网站内容及用户体验更好,企业会将动态URL地址伪装成静态地址提供服务。
  • 网址换新域名后,让旧的访问跳转到新的域名上。例如,访问京东的360buy.com会跳转到jd.com
  • 根据特殊变量、目录、客户端的信息进行URL调整等
server {

        listen 80;

        server_name abc.com;

        rewrite ^/(.*) http://www.abc.com/$1 permanent;

}

 

 

server {

        listen 80;

        server_name www.abc.com;

        location / {

                root /data/www/www;

                index index.html index.htm;

        }

        error_log    logs/error_www.abc.com.log error;

        access_log    logs/access_www.abc.com.log    main;

}

或者

server {

        listen 80;

        server_name abc.com www.abc.com;

        if ( $host != 'www.abc.com'  ) {

                rewrite ^/(.*) http://www.abc.com/$1 permanent;

        }

        location / {

                root /data/www/www;

                index index.html index.htm;

        }

        error_log    logs/error_www.abc.com.log error;

        access_log    logs/access_www.abc.com.log    main;

}

相关文章

网友评论

      本文标题:nginx的proxy_pass配置问题

      本文链接:https://www.haomeiwen.com/subject/piwinltx.html