Nginx 在端口 80 上运行,我使用它来反向代理 URL,并/foo以3200这种方式使用端口路径:
location /foo {
proxy_pass http://localhost:3200;
proxy_redirect off;
proxy_set_header Host $host;
}
Run Code Online (Sandbox Code Playgroud)
这工作正常,但我在 port 上有一个应用程序3200,我不希望将初始/foo值发送到该应用程序。也就是说 - 当我访问时http://localhost/foo/bar,我只想/bar成为应用程序接收到的路径。所以我尝试将此行添加到上面的位置块:
rewrite ^(.*)foo(.*)$ http://localhost:3200/$2 permanent;
Run Code Online (Sandbox Code Playgroud)
这会导致 302 重定向(更改 URL),但我想要 301。我该怎么办?
我不清楚负载均衡器和反向代理之间的区别。它们似乎都有相同的行为:将传入请求分发到后端服务器。
我最近听说 Nginx 为其反向代理功能添加了缓存。我环顾四周,但找不到太多关于它的信息。
我想将 Nginx 设置为 Apache/Django 前面的缓存反向代理:将一些(但不是全部)动态页面的 Nginx 代理请求发送到 Apache,然后缓存生成的页面并从缓存中为这些页面提供后续请求。
理想情况下,我想以两种方式使缓存无效:
是否可以设置 Nginx 来做到这一点?如何?
我用主机名运行了几个 docker 容器:
web1.local web2.local web3.local
由 nginx 根据主机名路由到这些。我在此设置(在连接到互联网的不同机器上)前面有一个代理,我将上游定义为:
upstream main {
server web1.local:80;
server web2.local:80;
server web3.local:80;
}
Run Code Online (Sandbox Code Playgroud)
和实际的虚拟主机描述:
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://main;
}
}
Run Code Online (Sandbox Code Playgroud)
现在,因为容器接收主机名“main”而不是“web1.local”,它们不能正确响应请求。
问题:如何在代理请求时告诉 nginx 在 Host: 标头中传递上游服务器的名称而不是上游服务器组的名称?
我有一个相当大的和缓慢的(复杂的数据,复杂的前端)的Web应用程序构建RoR并担任Puma与nginx作为反向代理。查看nginx错误日志,我看到很多条目,例如:
2014/04/08 09:46:08 [warn] 20058#0: *819237 an upstream response is buffered to a temporary file
/var/lib/nginx/proxy/8/47/0000038478 while reading upstream,
client: 5.144.169.242, server: engagement-console.foo.it,
request: "GET /elements/pending?customer_id=2&page=2 HTTP/1.0",
upstream: "http://unix:///home/deployer/apps/conversationflow/shared/sockets/puma.sock:/elements/pending?customer_id=2&page=2",
host: "ec.reputationmonitor.it",
referrer: "http://ec.foo.it/elements/pending?customer_id=2&page=3"
Run Code Online (Sandbox Code Playgroud)
我很好奇,因为对于不同的用户和不同的用户交互,页面不太可能保持相同,而且我不认为在磁盘上缓冲响应是必要的/有用的。
我知道proxy_max_temp_file_size并将其设置为 0,但在我看来有点尴尬(我的代理尝试缓冲但没有文件可以缓冲到...怎么能更快?)。
我的问题是:
如何删除 [warn] 并避免缓冲响应?关闭proxy_buffering还是设置proxy_max_temp_file_size为0更好?为什么?
如果nginx缓冲响应:它什么时候提供缓冲响应,给谁,为什么?
为什么默认情况下nginx打开proxy_buffering然后[警告]如果它实际上缓冲了响应?
响应何时触发该选项?当需要> 几秒钟(多少?)来提供响应时?这个可以配置吗?
TIA,ngw。
我在一台以 Host Header 区分的 IIS 6 服务器上设置了多个网站。
但是,我希望在我的网络上有一个由 Linux / Apache 服务器提供服务的站点。我是否需要为 IIS 使用反向代理加载项,或者是否有一种简单的方法可以告诉 IIS 将所有请求传递到另一台服务器?
我在 Apache 中有如下反向代理设置:
地址为 www.example.com/folder 的服务器 A 是反向代理服务器。
它映射到:地址为 test.madeupurl.com 的服务器 B
这种作品。但我遇到的问题是,在 www.example.com/folder 上,所有相关链接的形式都是 www.example.com/css/examplefilename.css 而不是 www.example.com/folder/css/examplefilename。 css
我该如何解决?
到目前为止,我的反向代理在服务器 A (www.example.com) 上有这个:
<Location /folder>
ProxyPass http://test.madeupurl.com
ProxyPassReverse http://test.madeupurl.com
</Location>
Run Code Online (Sandbox Code Playgroud) HTTP标头的维基百科描述X-Forwarded-For是:
X-Forwarded-For:client1、proxy1、proxy2、...
该指令的 nginx 文档real_ip_header部分内容如下:
该指令设置用于传输替换 IP 地址的标头的名称。
在 X-Forwarded-For 的情况下,此模块使用X-Forwarded-For 标头中的最后一个ip 进行替换。[强调我的]
这两种描述似乎相互矛盾。在我们的场景中,X-Forwarded-For标头与所描述的完全一样——客户端的“真实”IP 地址是最左边的条目。同样,nginx 的行为是使用最右边的值——很明显,它只是我们的代理服务器之一。
我的理解X-Real-IP是它应该用于确定实际的客户端 IP 地址——而不是代理。我是否遗漏了什么,或者这是 nginx 中的错误?
而且,除此之外,是否有人对如何使X-Real-IP标题显示最左边的值有任何建议,如 的定义所示X-Forwarded-For?
我尝试将 Nginx 服务器配置为反向代理,以便它从客户端收到的 https 请求也通过 https 转发到上游服务器。
这是我使用的配置:
http {
# enable reverse proxy
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwared-For $proxy_add_x_forwarded_for;
upstream streaming_example_com
{
server WEBSERVER_IP:443;
}
server
{
listen 443 default ssl;
server_name streaming.example.com;
access_log /tmp/nginx_reverse_access.log;
error_log /tmp/nginx_reverse_error.log;
root /usr/local/nginx/html;
index index.html;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_certificate /etc/nginx/ssl/example.com.crt;
ssl_certificate_key /etc/nginx/ssl/example.com.key;
ssl_verify_client off;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers RC4:HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location /
{
proxy_pass https://streaming_example_com;
}
}
}
Run Code Online (Sandbox Code Playgroud)
无论如何,当我尝试使用反向代理访问文件时,这是我在反向代理日志中得到的错误:
2014/03/20 12:09:07 [错误] 4113079#0:*1 SSL_do_handshake() …
我将 nginx 配置为我的外部可见网络服务器,它通过 HTTP 与后端通信。
我想要实现的场景是:
我当前的配置(后端配置正确)是:
服务器 {
听80;
server_name 本地主机;
位置 ~ .* {
proxy_pass http://backend;
proxy_redirect http://backend https://$host;
proxy_set_header 主机 $host;
}
}
我的问题是对客户端的响应(第 4 步)是通过 HTTP 而不是 HTTPS 发送的。有任何想法吗?
reverse-proxy ×10
nginx ×7
301-redirect ×1
apache-2.2 ×1
buffer ×1
http-headers ×1
https ×1
iis ×1
linux ×1
proxy ×1
ssl ×1
varnish ×1