Ruby 如何使用nginx proxy_pass保存请求url
我试图使用AppServer,但有一个问题 当nginx使用Ruby 如何使用nginx proxy_pass保存请求url,ruby,proxy,nginx,thin,unicorn,Ruby,Proxy,Nginx,Thin,Unicorn,我试图使用AppServer,但有一个问题 当nginx使用proxy\u pass将请求发送到瘦(或Unicorn)时http://my_app_upstream;应用程序接收nginx发送的修改后的URL(http://my_app_upstream) 我想要的是传递原始URL和来自客户端的原始请求,而不做任何修改,因为应用程序严重依赖它 nginx’说: 如果需要在中传输URI 未处理的表单then指令 应在没有URI的情况下使用proxy_pass 部分 但我不明白如何准确地配置它,因为
proxy\u pass将请求发送到瘦(或Unicorn)时http://my_app_upstream;
应用程序接收nginx发送的修改后的URL(http://my_app_upstream
)
我想要的是传递原始URL和来自客户端的原始请求,而不做任何修改,因为应用程序严重依赖它
nginx’说:
如果需要在中传输URI
未处理的表单then指令
应在没有URI的情况下使用proxy_pass
部分
但我不明白如何准确地配置它,因为相关示例实际上使用的是URI:
location /some/path/ {
proxy_pass http://127.0.0.1;
}
因此,您能帮我弄清楚如何保留来自客户端的原始请求URL吗?我认为该指令可以帮助:
location / {
proxy_pass http://my_app_upstream;
proxy_set_header Host $host;
# ...
}
只是
代理设置头主机$Host
波特小姐,我的案子。解决者:
location / {
proxy_pass http://BACKENDIP/;
include /etc/nginx/proxy.conf;
}
然后在proxy.conf中
proxy_redirect off;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
要在不截断请求的
绝对URI
和标头中的主机
的情况下完美地转发,请执行以下操作:
server {
listen 35005;
location / {
rewrite ^(.*)$ "://$http_host$uri$is_args$args";
rewrite ^(.*)$ "http$uri$is_args$args" break;
proxy_set_header Host $host;
proxy_pass https://deploy.org.local:35005;
}
}
在这里可以找到:nginx还提供了$http\u主机变量,它将为您传递端口。 它是主机和端口的连接 所以你只需要做:
proxy_set_header Host $http_host;
在我的场景中,我已经在nginx vhost配置中通过下面的代码实现了这一点
server {
server_name dashboards.etilize.com;
location / {
proxy_pass http://demo.etilize.com/dashboards/;
proxy_set_header Host $http_host;
}}
$http\u host将在头中设置与请求相同的URL如果有东西修改了您尝试提供服务的位置,例如
try\u文件
,这将保留对后端的请求:
location / {
proxy_pass http://127.0.0.1:8080$request_uri;
}
对于我的身份验证服务器。。。这很有效。我喜欢为我自己的人性化可读性提供/auth选项。。。或者,我还通过端口/上游为机器对机器进行配置 . 在会议开始时 在我的443服务器块内 在conf的底部
请注意,其他人发现这一点:解决方案的核心是 nginx不操纵URL,是为了删除URL末尾的斜杠 副本:proxy_pass指令。vs -雨果·约瑟夫森
我在上面的评论中发现了这一点,但我认为这确实应该是一个答案。请注意,其他人发现这一点:让nginx不操纵URL的解决方案的核心是删除
proxy\u pass
指令末尾的斜杠<代码>http://my_app_upstreamvshttp://my_app_upstream/
对我来说,当JSP执行重定向时,我的应用程序上游主机名出现了。使用proxy\u set\u header Host$Host
修改并使Tomcat/JSP认为它是实际的客户机请求的域。谢谢你的邀请help@HugoJosefson哇,感谢上帝,我注意到了你的帖子。答案中应该明确这一点在我的案例中,@HugoJosefson的解决方案不起作用。我指的是,;我必须设置标题。这是一个改进,但没有保留方案(http或https)。现在我的https://example.com/page
uri变为http://example.com/page
谢谢,这是我在代理后面的端点上进行OAuth验证时丢失的一块($server\u端口)。我正在使用sinatra的机架保护,并且在POST URL上被禁止。将端口添加到主机代理标头为我修复了它。我认为这在最新版本的Nginx中不再起作用
####################################################
upstream auth {
server 127.0.0.1:9011 weight=1 fail_timeout=300s;
keepalive 16;
}
if (-d $request_filename) {
rewrite [^/]$ $scheme://$http_host$uri/ permanent;
}
location /auth {
proxy_pass http://$http_host:9011;
proxy_set_header Origin http://$host;
proxy_set_header Host $http_host:9011;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
proxy_http_version 1.1;
}
#####################################################################
# #
# Proxies for all the Other servers on other ports upstream #
# #
#####################################################################
#######################
# Fusion #
#######################
server {
listen 9001 ssl;
############# Lock it down ################
# SSL certificate locations
ssl_certificate /etc/letsencrypt/live/allineed.app/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/allineed.app/privkey.pem;
# Exclusions
include snippets/exclusions.conf;
# Security
include snippets/security.conf;
include snippets/ssl.conf;
# Fastcgi cache rules
include snippets/fastcgi-cache.conf;
include snippets/limits.conf;
include snippets/nginx-cloudflare.conf;
########### Location upstream ##############
location ~ / {
proxy_pass http://auth;
proxy_set_header Origin http://$host;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
proxy_http_version 1.1;
}
if (-d $request_filename) {
rewrite [^/]$ $scheme://$http_host$uri/ permanent;
}
}