%20Proxy%2C%20Hinzuf%C3%BCgen%20benutzerdefinierter%20Header%20zu%20statischen%20Dateien.png)
Ich versuche, statischen Dateien Header hinzuzufügen. Wie mache ich das richtig?
Ich habe versucht, zu verschachteln, aber es hat nicht funktioniert
server {
location / {
proxy_pass http://apache.backend.local/;
proxy_no_cache $http_pragma $http_authorization;
proxy_cache radish_cache;
proxy_cache_bypass $http_cache_control;
add_header X-Proxy-Cache $upstream_cache_status;
proxy_redirect off;
proxy_pass_header Set-Cookie;
proxy_ignore_headers Cache-Control Expires;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header Accept-Encoding '';
proxy_set_header Connection '';
proxy_set_header Referer $http_referer;
proxy_set_header Cookie $http_cookie;
proxy_hide_header X-Powered-By;
proxy_connect_timeout 59s;
proxy_send_timeout 600;
proxy_read_timeout 600;
proxy_buffer_size 64k;
proxy_buffers 16 32k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 64k;
location ~* \.(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso)$ {
gzip_static off;
#add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
access_log off;
expires 30d;
break;
}
location ~* \.(js)$ {
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
access_log off;
expires 10d;
break;
}
location ~* \.(css)$ {
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
access_log off;
expires 10d;
break;
}
}
}
habe auch versucht, nicht zu verschachteln und die Proxy-Konfiguration an jedem Standort einzuschließen, dann bekomme ich diesen Fehler
"proxy_pass" cannot have URI part in location given by regular expression, or inside named location, or inside "if" statement, or inside "limit_except"
Ich verwende das neueste OpenResty
Antwort1
Das Ende /
der proxy_pass
Anweisung ist der in der Fehlermeldung erwähnte „URI-Teil“.
In Ihrer Konfigurationsdatei haben Sie:
location / {
proxy_pass http://apache.backend.local/;
...
}
Das Übersetzen /
(aus dem location
) in /
(aus der proxy_pass
Anweisung) ist sinnlos – daher ist der „URI-Teil“ unnötig und sollte entfernt werden.
Als Sie versuchten, proxy_pass
in verschiedenenregulären Ausdruck location
Blöcke, der „URI-Teil“ hat die Fehlermeldung ausgelöst. Da Sie aber keine proxy_pass
URI-Übersetzung durchführen müssen, können Sie das nachfolgende /
. bedenkenlos entfernen.
Sehendieses Dokumentfür Details.