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