nginx 配置路由规则转发配置记录


工作中公司要求针对经销商PC端和工厂PC端的访问地址固定访问。

经销商PC端 http://localhost/

工厂PC端   http://localhost/fac

 

文件磁盘路径:

/crm/nginx-pages

  |---- admin

  |---- adminfac

 

 经销商端:

 

location ^~ /admin {
               root /crm/nginx-pages/;
               index index.html;
               rewrite ^/admin/(.*)\.*$ /admin/$1 break;
        }

 

 

 

  工厂端:

location ^~ /adminfac {
               root /crm/nginx-pages/;
               index index.html;
               rewrite ^/adminfac/(.*)\.*$ /adminfac/$1 break;
        }

 

 

路由定向:

location / {
               if ($uri = /) {
                  rewrite / http://$host/admin? permanent;
               }
               if ($uri = /fac) {
                  rewrite /fac http://$host/adminfac? permanent;
               }
               #try_files $uri $uri/ =404;
        }

 针对url地址和nginx映射磁盘地址不一致处理。

 

nginx 定向参数:
last - 完成重写指令,之后搜索相应的URI或location。 break - 完成重写指令。 redirect - 返回302临时重定向,如果替换字段用http://开头则被使用。 permanent - 返回301永久重定向。

 

其它命令:

nginx -t -c /etc/nginx/nginx.conf #nginx校验配置文件是否可用
nginx -s reload #nginx重新加载
nginx -s stop #nginx停止
nginx -c /etc/nginx/bginx.conf #nginx启动

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM