[英]Reroute NGINX path to another path (without http redirect)
我希望能夠轉到下面的這些URL
http://assets.mydomain.com/static/style.css
http://assets.mydomain.com/v999/static/style.css
在NGINX中,上述任一網址應改為指向
/var/www/vhosts/mysite/public/static/style.css
我怎樣才能做到這一點? 我以為這只是做別名的情況,但事實並非如此
即。
location ~* ^/v(.*)/ {
alias $rootPath;
}
但這似乎不起作用。 以下是我完整的nginx配置。
server {
set $rootPath /var/www/vhosts/mysite/public;
listen 80;
server_name assets.mydomain.com;
root $rootPath;
access_log /var/log/nginx/access_assets.log;
error_log /var/log/nginx/error_assets.log debug;
index index.html index.htm;
# Any files matching these extensions are cached for a long time
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires max;
add_header Cache-Control public;
}
# Don't throw any errors for missing favicons and don't display them in the logs
location /favicon.ico {
log_not_found off;
access_log off;
error_log off;
}
# Deny these extensions
location ~* \.(txt|php|less)$ {
deny all;
}
# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
# Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
location ~ /\. {
deny all;
}
location ~* ^/v(.*)/ {
alias $rootPath;
}
location / {
try_files $uri $uri/;
}
}
您只需要:
server {
set $rootPath /var/www/vhosts/mysite/public;
listen 80;
server_name assets.mydomain.com;
root $rootPath;
location /v999/ {
root $rootPath;
}
...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.