Nginx - configure location regex for all static file in sub alias -
i've been trying 1 day no luck configure nginx proxy reverse apache. expect nginx serve static file, , rest passed apache.
it's not hard achieve if site resides on root domain name.
for example, i've set:
www.mydomain.com location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml|rss|txt)$ { root /path/to/mysite; } location / { proxy_pass 127.0.0.1:8080; proxy_set_header host $host; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; proxy_set_header x-real-ip $remote_addr; }
now problem arises want configure site within alias example: www.mydomain.com/site1
does know how achieve same purpose?
i tried below configuration doesn't work:
location /site1 { location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml|rss|txt)$ { root /path/to/anothersite1; } proxy_pass apache:8080; proxy_set_header host $host; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; proxy_set_header x-real-ip $remote_addr; }
the problem 'root' directive doesn't replace /site1 uri. example, request to
www.mydomain.com/site1/folder/pic.jpg
will handled opening file:
/path/to/anothersite1/site1/folder/pic.jpg;
instead of:
/path/to/anothersite1/folder/pic.jpg
i appreciate on this. i've tried replace 'root' directive 'alias' still no luck.
thanks beforehand,
try add rewrite directive in sub location. this:
location /site1 { location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml|rss|txt)$ { rewrite "^/site1/(.*)$" /$1 break; root /path/to/anothersite1; } proxy_pass apache:8080; proxy_set_header host $host; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; proxy_set_header x-real-ip $remote_addr; }
Comments
Post a Comment