Nginx//u7684location//u914d//u7f6e//u7528//u4e8e//u5339//u914d//u7279//u5b9a//u7684URL//u8def//u5f84//uff0c//u5e76//u6307//u5b9a//u76f8//u5e94//u7684//u5904//u7406//u65b9//u5f0f//u3002//u4ee5//u4e0b//u662f//u4e00//u4e9b//u5e38//u89c1//u7684location//u914d//u7f6e//u793a//u4f8b//uff1a//n//n1//u3002//u9759//u6b63//u6587//u4ef6//u670d//u52a1//uff1a//nlocation /static/ {//n root /var/www/;//n}//n//n//u4e0a//u8ff0//u914d//u7f6e//u5c06//u5339//u914d//u4ee5/static///u5f00//u59cb//u7684URL//u8def//u5f84//uff0c//u5e76//u5728/var/www///u76ee//u5f52//u4e0b//u627e//u5230//u76f8//u5e94//u7684//u6587//u4ef6//u3002//n//n2//u3002//u53cd//u5411//u4ee3//u7406//uff1a//nlocation /api/ {//n proxy_pass http://backend_server;//n}//n//n//u4e0a//u8ff0//u914d//u7f6e//u5c06//u5339//u914d//u4ee5/api///u5f00//u59cb//u7684URL//u8def//u5f84//uff0c//u5e76//u5c06//u8bf7//u6c42//u8f6c//u53d1//u7ed9backend_server//u3002//n//n3//u3002//u6b63//u5219//u8868//u8fbe//u5f0f//u5339//u914d//uff1a//nlocation ~ ^/user/(/d+)/ {//n ...//n}//n//n//u4e0a//u8ff0//u914d//u7f6e//u5c06//u5339//u914d//u4ee5/user///u5f00//u59cb//uff0c//u540e//u9762//u8ddf//u7740//u4e00//u4e2a//u6216//u591a//u4e2a//u6570//u5b57//u7684URL//u8def//u5f84//u3002//n//n4//u3002//u91cd//u5411//u5bfc//u5411//uff1a//nlocation /old/ {//n return 301 /new/;//n}//n//n//u4e0a//u8ff0//u914d//u7f6e//u5c06//u5339//u914d//u4ee5/old///u5f00//u59cb//u7684URL//u8def//u5f84//uff0c//u5e76//u5c06//u8bf7//u6c42//u91cd//u5411//u5bfc//u5411//u5230/new///u3002//n//n5//u3002//u4f7f//u7528//u6b63//u5219//u8868//u8fbe//u5f0f//u8fdb//u884cURL//u91cd//u5199//uff1a//nlocation ~ ^/blog/(.*)$ {//n rewrite ^/blog/(.*)$ /$1 break;//n}//n//n//u4e0a//u8ff0//u914d//u7f6e//u5c06//u5339//u914d//u4ee5/blog///u5f00//u59cb//u7684URL//u8def//u5f84//uff0c//u5e76//u5c06/blog///u540e//u9762//u7684//u5185//u5bb9//u91cd//u5199//u5230//u6839//u76ee//u5f52//u3002//n//n//u8fd9//u4e9b//u53ea//u662f//u4e00//u4e9b//u5e38//u89c1//u7684location//u914d//u7f6e//u793a//u4f8b//uff0c//u4f60//u53ef//u4ee5//u6839//u636e//u5b9e//u9645//u9700//u6c42//u8fdb//u884c//u66f4//u590d//u6742//u7684//u914d//u7f6e//u3002//u66f4//u8be6//u7ec6//u7684//u914d//u7f6e//u8bf4//u660e//u53ef//u4ee5//u53c2//u8003Nginx//u516c//u5f00//u6587//u6863//u3002

Nginx Location 配置详解:匹配URL路径、静态文件、反向代理、重定向

原文地址: https://www.cveoy.top/t/topic/pv91 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录