标签: proxypass

Nginx反向代理导致504网关超时

我使用Nginx作为反向代理,接受请求,然后执行proxy_pass从端口8001上运行的上游服务器获取实际的Web应用程序.

如果我去mywebsite.com或做一个wget,我会在60秒后获得504网关超时...但是,如果我加载mywebsite.com:8001,应用程序会按预期加载!

因此有些事情阻止了Nginx与上游服务器的通信.

所有这一切都是在我的托管公司重置机器运行之后开始的,之前没有任何问题.

这是我的vhosts服务器块:

server {
    listen   80;
    server_name mywebsite.com;

    root /home/user/public_html/mywebsite.com/public;

    access_log /home/user/public_html/mywebsite.com/log/access.log upstreamlog;
    error_log /home/user/public_html/mywebsite.com/log/error.log;

    location / {
        proxy_pass http://xxx.xxx.xxx.xxx:8001;
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
} 
Run Code Online (Sandbox Code Playgroud)

我的Nginx错误日志输出:

2014/06/27 13:10:58 [error] 31406#0: *1 upstream timed out (110: Connection timed out) while connecting to upstream, client: xxx.xx.xxx.xxx, server: mywebsite.com, request: "GET / HTTP/1.1", upstream: "http://xxx.xxx.xxx.xxx:8001/", host: "mywebsite.com"
Run Code Online (Sandbox Code Playgroud)

reverse-proxy nginx proxypass http-status-code-504

103
推荐指数
6
解决办法
16万
查看次数

如果找不到上游主机,则设置nginx不会崩溃

我们在Docker的常见域下有几个rails应用程序,我们使用nginx将请求定向到特定应用程序.

our_dev_server.com/foo # proxies to foo app
our_dev_server.com/bar # proxies to bar
Run Code Online (Sandbox Code Playgroud)

Config看起来像这样:

upstream foo {
  server foo:3000;
}

upstream bar {
  server bar:3000;
}

# and about 10 more...

server {
  listen *:80 default_server;

  server_name our_dev_server.com;

  location /foo {
      # this is specific to asset management in rails dev
      rewrite ^/foo/assets(/.*)$ /assets/$1 break;
      rewrite ^/foo(/.*)$ /foo/$1 break;
      proxy_pass http://foo;
  }

  location /bar {
      rewrite ^/bar/assets(/.*)$ /assets/$1 break;
      rewrite ^/bar(/.*)$ /bar/$1 break;
      proxy_pass http://bar;
  }

  # and about 10 more... …
Run Code Online (Sandbox Code Playgroud)

nginx url-rewriting proxypass

94
推荐指数
4
解决办法
4万
查看次数

如何在使用proxy_pass时在nginx上添加响应头?

我想为从nginx后面的服务器收到的响应添加自定义标头.

虽然add_header适用于nginx处理的响应,但在proxy_pass使用时它什么都不做.

nginx proxypass http-headers

78
推荐指数
5
解决办法
13万
查看次数

设置HTTP代理以插入标头

我需要测试一些与客户端的HTTP交互,而不是修改.我需要测试的是当客户端的请求包含某个静态头时服务器的行为.

我认为运行此测试的最简单方法是设置一个HTTP代理,在每个请求上插入标头.设置它的最简单方法是什么?

apache proxy proxypass http-headers

46
推荐指数
2
解决办法
10万
查看次数

apache ProxyPass:如何保留原始IP地址

我们使用ProxyPass将所有"/ r"请求重定向到端口18080上的jboss,如下所示:

ProxyPreserveHost on
ProxyPass /r http://localhost:18080/redirectService/
ProxyPassReverse /r http://localhost:18080/redirectService/
Run Code Online (Sandbox Code Playgroud)

但是,这会导致jboss访问日志中记录的IP地址为"127.0.0.1".有人知道我们如何保留HttpServletRequest中请求所在的原始IP?我们希望在doGet()中从jboss servlet请求中获取它

apache redirect proxypass

39
推荐指数
5
解决办法
10万
查看次数

使用$ remote_addr的Nginx proxy_pass

我试图在我的proxy_pass上包含$ remote_addr或$ http_remote_addr但没有成功.

重写规则有效

location ^~ /freegeoip/ {  
  rewrite ^ http://freegeoip.net/json/$remote_addr last;
}
Run Code Online (Sandbox Code Playgroud)

没有$ remote_addr的proxy_pass有效,但freegeoip不读取x-Real-IP

location ^~ /freegeoip/ {
  proxy_pass http://freegeoip.net/json/;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header Host $host;
}
Run Code Online (Sandbox Code Playgroud)

然后,我将ip添加到请求的末尾,如下所示:

location ^~ /freegeoip/ {
  proxy_pass http://freegeoip.net/json/$remote_addr;
}
Run Code Online (Sandbox Code Playgroud)

但是nginx报告此错误:没有定义解析器来解析freegeoip.net

nginx proxypass

36
推荐指数
3
解决办法
5万
查看次数

收到带签名的Ajp无效邮件

我正在使用Tomcat 7.0.29前面的Apache 2.2.22 modproxy.配置Ajp作为httpd.conf中的协议和server.xml中的AjpNioProtocol.服务器启动后,日志将填充以下消息:

严重:收到签名
20599 com.apache.coyote.ajp.AjpMessage processHeader的消息无效

没有请求发送到Web或tomcat服务器,它仍然会抛出该错误.tomcat和apache中的访问日志显示没有请求进入.导致无效消息错误的原因是什么?

这是配置:

apache2 mod-proxy proxypass tomcat7

22
推荐指数
2
解决办法
6万
查看次数

NginX在代理传递URL中尾随斜杠

我知道这个问题已被多次询问,但在尝试了很多解决方案后,我仍然被卡住了.

我正在使用NginX代理传递给NodeJs应用程序.我正在尝试让url https://example.com代理传递请求http://example.com:8080/?

请求(来自移动应用程序)正在请求https://example.com//哪个nginx正在进行http://example.com:8080//?哪些无效.

我尝试过但没有奏效的事情:

  • merge_slashes on; (默认情况下已启用)
  • rewrite ^/(.*)/$ /$1 permanent;
  • port_in_redirect off;

我的nginx配置:

location = /a {
    proxy_pass http://127.0.0.1:8080;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_read_timeout 300;
}

location ^~ /a/ {
    proxy_pass http://127.0.0.1:8080;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_read_timeout 300;
}
Run Code Online (Sandbox Code Playgroud)

proxy nginx proxypass

22
推荐指数
1
解决办法
3万
查看次数

https重定向为代理后面的rails app?

我的nginx.conf中的服务器声明:

    listen       1.2.3.4:443 ssl;
    root /var/www/myapp/current/public;
    ssl on;
    ssl_certificate /etc/nginx-cert/server.crt;
    ssl_certificate_key /etc/nginx-cert/server.key;
    location / {
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header Host $http_host;
          proxy_redirect off;

          if (!-f $request_filename) {
            proxy_pass http://upstreamy;
            break;
          }
     }
Run Code Online (Sandbox Code Playgroud)

nginx.conf中的上游声明:

upstream upstreamy {
    server unix:/var/www//myapp/shared/sockets/unicorn.sock fail_timeout=0;
}
Run Code Online (Sandbox Code Playgroud)

这工作正常,myapp可以访问为https:// somehost

但该应用程序正在为重定向生成http url,因此例如在使用devise进行身份验证时,/会被重定向到http:// somehost/user/sign_in而不是https(从rails应用程序的角度来看,无论如何都是http).

我试过了

proxy_pass https://upstreamy;
Run Code Online (Sandbox Code Playgroud)

但这只是试图加密nginx和运行rails app的独角兽之间的流量.

我也试过,在application_helper.rb中:

# http://stackoverflow.com/questions/1662262/rails-redirect-with-https
def url_options
  super
  @_url_options.dup.tap do |options|
  options[:protocol] = Rails.env.production? ? "https://" : "http://"
  options.freeze
end
Run Code Online (Sandbox Code Playgroud)

但似乎行不通.

如何解决这个问题?

编辑:所以,目标不是让rails应用程序需要ssl,或者强制使用ssl; 目标是让rails应用程序在重定向时生成https:// urls ...(我认为所有其他网址都是相对的).

https ruby-on-rails nginx proxypass unicorn

20
推荐指数
1
解决办法
1万
查看次数

一个域上的ProxyPass和DocumentRoot

假设我有以下配置:

<VirtualHost domain.com>
    # Server names, admins, logs etc...

    ProxyVia On
    ProxyRequests Off
    <Location "/">
        ProxyPass http://localhost:8080/tomcat-webapp/
        ProxyPassReverse http://localhost:8080/tomcat-webapp/
        Order allow,deny
        Allow from all
    </Location>
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

现在,我希望地址domain.com/forum显示我的MyBB论坛的内容,哪些文件在/var/www/forum目录中.怎么做到这一点?

apache proxypass document-root

18
推荐指数
1
解决办法
2万
查看次数