Closed opskumu closed 5 years ago
server {
... ...
location / {
error_page 404 = @foobar;
}
location @foobar {
rewrite .* / permanent;
}
... ...
}
proxy_pass
Sets the protocol and address of a proxied server and an optional URI to which a location should be mapped. As a protocol, “http” or “https” can be specified. The address can be specified as a domain name or IP address, and an optional port:
proxy_pass http://localhost:8000/uri/;
or as a UNIX-domain socket path specified after the word “unix” and enclosed in colons:
proxy_pass http://unix:/tmp/backend.socket:/uri/;
If a domain name resolves to several addresses, all of them will be used in a round-robin fashion. In addition, an address can be specified as a server group.
A request URI is passed to the server as follows:
也就是:http://127.0.0.1/name/ --> http://127.0.0.1/remote/
location /name/ {
proxy_pass http://127.0.0.1/remote/;
}
如果 proxy_pass
中没有添加 URI
,那么请求 URI
会传递过去,请求是什么就是什么。
也就是: http://127.0.0.1/some/path/ --> http://127.0.0.1/some/path/
location /some/path/ {
proxy_pass http://127.0.0.1;
}
Before version 1.1.12, if proxy_pass is specified without a URI, the original request URI might be passed instead of the changed URI in some cases.
server {
listen 80;
server_name www.test.com;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8000;
}
location /static {
alias /data/www/project/app/static;
}
... ...
}
location = /en {
return 302 /en/;
}
location /en/ {
proxy_pass http://luscious/; # note the trailing slash here, it matters!
}