[英]make a subdirectory show the content of a subdomain in nginx
我想處理:
blog.example.com => example.com/blog
blog.example.com/xxx => example.com/blog/xxx
在這兩個示例中,博客子目錄中都沒有任何內容,應該處理博客的代碼位於子域中。 而我只想顯示上面顯示的網址。
所以。 我想將子目錄轉發(重定向而不更改url)到子域。
是否有任何nginx配置可以做到這一點?
您的NGINX配置中可能包含以下內容。
server {
listen 80;
server_name blog.example.com;
location / {
return 301 $scheme://example.com/blog$request_uri;
}
}
server {
listen 80;
server_name example.com;
location /blog/ {
<your code goes here>
}
}
這會將所有傳入請求都發送到blog.example.com
並重定向到example.com/blog
以及所請求的URI,例如。 blog.example.com/latest
將重定向到example.com/blog/latest
location = /blog {
return 302 /blog/;
}
location /blog/ {
proxy_pass http://blog.example.com/;
}
請注意, proxy_pass
中的/
非常重要(沒有它, /blog
部分將不會在上游請求中被剝離)。
有關兩個獨立location
聲明的原理的更多詳細信息,請參見https://serverfault.com/questions/562756/how-to-remove-the-path-with-an-nginx-proxy-pass/562850#562850 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.