I am using nginx to proxy a directory to a remote server, with the code:
location /directory/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host sub.domain.io;
proxy_pass http://sub.domain.io:80/;
}
However, various static files like CSS break due to other rules I have after this.
Is there a way I can end the processing once matched to this directory? In the same way you can use last for rewrites.
Here is the full config:
root /var/www/site;
autoindex off;
index index.php;
charset utf-8;
log_not_found off;
access_log /var/www/site/data/logs/access.log;
error_log /var/www/site/data/logs/error.log;
add_header X-debug-message "$geoip_country_code" always;
location ~ \.php$
{
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
location ~ "^/(de|es|fr)*$" {
set $lang "$1/";
set $page 'homepage';
if ($http_accept_encoding !~ gzip) {
rewrite ^/(.*)$ /index.php?request=/ last;
}
try_files /data/cache/html/$lang$page.html.gz @php;
add_header Content-Encoding gzip;
gzip off;
default_type text/html;
}
location /directory/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host sub.domain.io;
proxy_pass http://sub.domain.io:80/;
}
if ($allowed_country = no) {
return 444;
}
location /
{
try_files $uri @main_cache;
}
location @main_cache {
if ($http_accept_encoding !~ gzip) {
rewrite ^/(.*)$ /index.php?request=$1 last;
}
if ( $query_string ) {
rewrite ^/(.*)$ /index.php?request=$1 last;
}
try_files /data/cache/html$uri.html.gz @php;
add_header Content-Encoding gzip;
gzip off;
default_type text/html;
}
location @php {
rewrite ^/(.+)$ /index.php?request=$1 last;
}
location /data/cache/pred
{
try_files $uri $uri/ =404;
if ( !-e $request_filename )
{
rewrite /cache/ps/(.*)$ /index.php?request=get&pin=$1 last;
break;
}
}
location ~* \.(eot|ico|jpe?g|png|svg|ttf|woff|woff2)$
{
gzip_static on;
gzip_vary on;
expires 30d;
add_header Cache-Control "public";
}
location ~* \.(css|js)$
{
gzip_static on;
gzip_vary on;
expires 7d;
add_header Cache-Control "public";
}
location ~ ^/(src|cron|tpl)
{
return 301 $scheme://$server_name;
}
The request ends up as a 404 on the source server. It only ends up like that for the file formats listed in the penultimate two blocks.