标签: reverse-proxy

nginx反向代理到mongodb rest接口

我正在尝试使用代理 MongoDB 的 REST 接口的 HTTP 身份验证设置反向代理。到目前为止,我有这个:

server {
        listen 80;
        server_name tld.example.com;
        charset utf-8;
        access_log /home/jill/logs/nginx.access.log main;

        # Redirect all HTTP traffic to HTTPS URL
        rewrite ^(.*) https://tld.example.com$1 permanent;
}

server {
        listen 443;
        server_name tld.example.com;

        ssl on;
        ssl_prefer_server_ciphers on;
        ssl_protocols           TLSv1 SSLv3;
        ssl_ciphers             HIGH:!ADH:!MD5:@STRENGTH;
        ssl_session_cache       shared:TLSSL:16m;
        ssl_session_timeout     10m;
        ssl_certificate /path/to/cert/tld.example.com.bundle.crt;
        ssl_certificate_key /path/to/cert/tld.example.com.key;

        gzip on;
        gzip_vary on;
        gzip_comp_level 6;

        keepalive_timeout 300;
        keepalive_requests 500;

        location / {
                proxy_pass https://127.0.0.1:28017;

                proxy_redirect     off;

                proxy_max_temp_file_size 0;

                proxy_connect_timeout      90;
                proxy_send_timeout         90;
                proxy_read_timeout         90;

                proxy_buffer_size …
Run Code Online (Sandbox Code Playgroud)

nginx reverse-proxy mongodb

4
推荐指数
1
解决办法
4786
查看次数

NGINX 代理缓存 - 在查询字符串中缓存 buster 变量 - 可以忽略吗?

我们有以下 url 我们想要代理缓存:

file.php?parameter=one&paramater2=two&r=EPOCHTIMESTAMP
Run Code Online (Sandbox Code Playgroud)

查询字符串参数“参数”因请求而异。“paramater2”也是如此。

查询字符串参数 r 是我们用来确保客户端不提供缓存(在客户端)内容的时间戳。又名“缓存破坏者”。是的,我们还使用了所有适当的不缓存 h 标头。

现在,我们想通过 nginx 代理缓存其中的一些请求。是否可以指示 nginx 忽略 r 查询字符串参数,但在为条目设置缓存键时使用所有其他参数?如果我们不能忽略参数 r,那么 nginx 代理缓存将毫无用处,因为每个缓存键都是唯一的。

谢谢。

nginx cache reverse-proxy querystring

4
推荐指数
1
解决办法
5162
查看次数

nginx try_files 的奇怪行为。我的配置有什么问题?

os: debian stable (squeeze) nginx:squeeze-backports 1.2.1-2~bpo60+1

try_files 对我来说很奇怪。

这按预期工作,如果未找到 $uri,则在本地尝试 -> 使用 @static 位置

try_files  $uri $uri/ @static;
Run Code Online (Sandbox Code Playgroud)

仅在末尾添加 =404 会导致 404。如果我访问位于 $uri 或 @static 的现有文件,它是否仍然有效,并且仅在 @static 位置上找不到任何内容时才提供 404?

try_files  $uri $uri/ @static =404;
Run Code Online (Sandbox Code Playgroud)

将 =404 放在 @static 之前使其再次工作。为什么?如果文件不在 $uri 或 $uri/ 位置,而是在 @static 上,它应该导致 404 因为 =404 是在 @static 之前(根据我的理解)。如果我访问一个位于 $uri 的文件,它会从 nginx 正确提供(不访问 @static 后端或 =404)

try_files  $uri $uri/ =404 @static ;
Run Code Online (Sandbox Code Playgroud)

我很困惑

编辑:我的目标是:测试文件是否在本地,然后检查该文件的所有上游服务器,如果在这些位置找不到,则返回 404

配置:

upstream domain.com_upstream
{
    server yyy.yyy.yyy.yyy:8000 weight=10 max_fails=3 fail_timeout=3s;
    server zzz.zzz.zzz.zzz:8020 …
Run Code Online (Sandbox Code Playgroud)

nginx reverse-proxy

4
推荐指数
1
解决办法
5416
查看次数

使用 nginx 反向代理进行重定向

我有a.b域(例如)并希望username.github.io/project在a.b/c. 这意味着我还想将我的浏览器 url 保留a.b/c为username.github.io/project.

我在 nginx 模块中有以下设置

location /c {       
    proxy_pass http://username.github.io/project;
    proxy_redirect http://username.github.io http://a.b;
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_buffering off;
}
Run Code Online (Sandbox Code Playgroud)

如果我更改proxy_set_header Host $http_host为proxy_set_header Host $proxy_hostor $host,它只是重定向到http://username.github.io/project我不想要的。我能怎么做?

nginx proxy reverse-proxy redirect

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

会话在 tomcat 中丢失,使用 nginx 作为代理

我在 tomcar 服务器中有几个应用程序。我使用 nginx 作为代理,所以我可以实现从子域加入应用程序

tomat:8080/app1 > app1.mydomain.com 
tomat:8080/app2 > app2.mydomain.com 
Run Code Online (Sandbox Code Playgroud)

我设置了一个反向代理:

server {
  listen 80;
  server_name  app1.mydomain.com;
  location / {
   proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
      proxy_set_header X-Forwarded-Host $host;
     proxy_set_header X-Forwarded-Server $host;

    proxy_pass http://tomcat:8080/app1/;
  }
}
Run Code Online (Sandbox Code Playgroud)

我可以毫无问题地访问该应用程序。但它无法保持会话。我在码头有另一个应用程序,它在 ngix 后面运行没有问题。此外,如果我直接访问应用程序,我可以毫无问题地操作它。

任何提示?

谢谢。

tomcat nginx reverse-proxy apache-2.2

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

Nginx:将 http 和 https 根重定向到子目录

我试图将 nginx 中 http 和 https 的根域重定向到同一个子目录 (https):

所以例如

http://example.com -> https://example.com/subdirectory

https://example.com -> https://example.com/subdirectory
Run Code Online (Sandbox Code Playgroud)

这在我看来很简单,但我正在努力实现这一目标。我试过使用重写的变体并返回 301,但总是以重定向循环结束。

我当前的配置(导致循环):

server {
        listen      80;
        server_name example.com;
        return 301 https://$server_name/subdirectory;
        }
server {
        listen 443 ssl spdy;
        server_name example.com;
        return 301 https://$server_name/subdirectory;
    }
Run Code Online (Sandbox Code Playgroud)

所以基本上,我试图从根域重定向到 https 上的相同子目录,无论根域是通过 http 还是 https 请求的。

nginx reverse-proxy 301-redirect

4
推荐指数
1
解决办法
4367
查看次数

nginx反向代理文件夹

我正在尝试使用反向代理访问另一个服务器后面的服务器。“主”服务器位于 mydomain.com 后面,我想使用 mydomain.com/test 访问第二个服务器。目前只有 mydomain.com/test 有效。

但是,如果我尝试访问 mydomain.com/test/myfiles,我将被重定向到不存在的 mydomain.com/myfiles,因为此 url 以“主”服务器为目标,因此出现 404 not found。我用proxy_redirect尝试了多种方法,重写但没有任何效果。

server {
    listen   80;
    index index.php index.html index.htm;
    root /path/to/content;
    server_name localhost mydomain.com;

    location / {
        try_files $uri $uri/ =404; #/index.html;
    }

    location /test/ {
        proxy_pass http://192.168.1.202/;
        proxy_set_header Host $host;
    }

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }
}
Run Code Online (Sandbox Code Playgroud)

curl -I "http://192.168.1.202" -H "Host: mydomain.com" 在主服务器上给出:

HTTP/1.1 301 Moved Permanently
Server: nginx/1.2.1
Date: Sun, 02 Nov 2014 15:02:56 GMT
Content-Type: text/html …
Run Code Online (Sandbox Code Playgroud)

nginx reverse-proxy

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

ProxyHTMLURLMap 在 apache2.4 中不起作用

我在 ubuntu 14.04 上使用 apache2.4。我启用了 mod_proxy_html。但是我的 URL 没有被新的 URL 取代。我在 apache2.2 中做了同样的事情,它运行良好。这是我的虚拟主机文件。

<VirtualHost *:80>
ServerAdmin webmaster@example.com
ServerName www.example.com
ServerAlias example.com
DocumentRoot /var/www/html/www.example.com
LogLevel error
CustomLog /var/log/apache2/www.example.com_access.log combined
ErrorLog /var/log/apache2/www.example.com_error.log

#Proxy and cookies settings
ProxyPreserveHost On
ProxyPassReverse / http://www.example.com/example/control/
ProxyPassReverse / https://www.example.com/example/control/
ProxyPassReverse / /example/control/
ProxyPassReverseCookiePath /example /

    <Proxy balancer://cluster>
        BalancerMember ajp://10.14.78.45:8009 route=node01 keepalive=On loadfactor=1 ping=10 ttl=600
        ProxySet timeout=60 stickysession=JSESSIONID nofailover=On
    </Proxy>

RewriteEngine On

#redirect non www domain to www domain
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
    RewriteRule ^(.*)$ http://www.example.com$1 [R=301,L]

#Website    
RewriteRule …
Run Code Online (Sandbox Code Playgroud)

mod-rewrite reverse-proxy apache-2.2 apache-2.4

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

当 Varnish 可以充当负载均衡器时,是否仍然需要 HAProxy?

我想对我的应用程序服务器进行负载平衡,并缓存来自它们的响应。

我在 HAProxy 的网站上阅读了 2012 年的一篇文章,该文章旨在消除 HAProxy 和 Varnish 之间的混淆:

http://blog.haproxy.com/2012/07/04/haproxy-and-varnish-comparison/

这篇文章基本上说HAProxy只是一个反向代理负载均衡器(无缓存),而Varnish是一个反向代理缓存(无负载均衡),因此它们是互补的。

但是今天,我可以在 Varnish 文档中看到它也进行负载平衡:

https://www.varnish-cache.org/trac/wiki/LoadBalancing

所以我只能猜测这个功能是从2012年开始引入的,现在在负载均衡方面直接与HAProxy竞争。

现在考虑到我需要一个反向代理缓存 + 负载平衡器,我是否可以只使用带有 Varnish 的单个服务器,这两者都可以吗?与典型的 HAProxy <-> Varnish 设置相比,可能有什么限制?

varnish reverse-proxy load-balancing haproxy

4
推荐指数
1
解决办法
3937
查看次数

Nginx 反向代理透传客户端证书

我正在尝试通过 Nginx 反向代理设置负载均衡器。我的应用程序使用客户端证书来验证客户端。我希望我的反向代理将客户端证书转发到我的后端服务器。我已将此行添加到反向代理的配置中,以将客户端证书信息存储在自定义 HTTP 标头中:

proxy_set_header X-SSL-CERT $ssl_client_cert
Run Code Online (Sandbox Code Playgroud)

但是,$ssl_client_cert使用多行来存储证书,并且我的后端 nginx 服务器无法将其正确识别为一个 HTTP 标头。实现转发我的客户证书的最佳方法是什么?

这个问题在 2013 年在这个论坛上被问过,但到目前为止还没有真正的解决方案:https : //forum.nginx.org/read.php?2,236546,236546

谢谢!

ssl nginx https reverse-proxy http-headers

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