我想将Nginx设置为https服务的反向代理,因为我们有一个特殊的用例,我们需要"取消https"连接:
http://nginx_server:8080/myserver ==> https://mysecureservice
但是会发生的是实际的https服务没有被代理.Nginx会将我重定向到实际服务,因此浏览器中的URL会发生变化.我想与Nginx进行交互,因为它是实际的服务,只是没有https.
这就是我所拥有的:
server {
listen 0.0.0.0:8080 default_server;
location /myserver {
proxy_pass https://myserver/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
}
}
Run Code Online (Sandbox Code Playgroud) 基本上我的情况是我有一个内部网站,需要一个单一的硬编码用户名和密码才能访问(这不能关闭,只能更改).我出于各种原因通过反向代理公开这个网站(隐藏端口,简化网址,简化NAT等).
但是,我想要做的是能够使用Apache来处理身份验证,以便:
编辑:关于更丰富的身份验证的第二部分已移至新问题
这或多或少是我现在所拥有的:
<VirtualHost *:80>
ServerName sub.domain.com
ProxyPass / http://192.168.1.253:8080/endpoint
ProxyPassReverse / http://192.168.1.253:8080/endpoint
# The endpoint has a mandatory password that I want to avoid requiring users to type
# I.e. something like this would be nice (but does not work)
# ProxyPass / http://username:password@192.168.1.253:8080/endpoint
# ProxyPassReverse / http://username:password@192.168.1.253:8080/endpoint
# Also need to be able to require a password to access proxy for people outside local subnet
# However these passwords will be …Run Code Online (Sandbox Code Playgroud) 我正在实现一个反向代理,用于将请求路由到后端服务器.
功能上一切正常,但是我担心来自后端服务器的所有响应都会在没有压缩的情况下传输到客户端(Web浏览器).
设置如下:
https://internal.apphttps://site.com.我想所有请求路由到https://site.com/app/WHATEVER到https://internal.app/WHATEVER的方式是透明的客户.
我当前的设置基于URL Rewrite 2.0和Application Request Routing IIS扩展.一般方法基于以下文章的指导原则:
有关节web.config的的site.com应用程序:
<system.webServer>
<rewrite>
<rules>
<rule name="Route the requests for backend app" stopProcessing="true">
<match url="^app/(.*)" />
<conditions>
<add input="{CACHE_URL}" pattern="^(https?)://" />
</conditions>
<action type="Rewrite" url="{C:1}://internal.app/{R:1}" />
<serverVariables>
<set name="HTTP_ACCEPT_ENCODING" value="" />
</serverVariables>
</rule>
</rules>
<outboundRules>
<rule name="RewriteBackendAbsoluteUrlsInResponse" preCondition="ResponseIsHtml1">
<match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^http(s)?://internal.app(\:80)?/(.*)" />
<action type="Rewrite" value="/app/{R:3}" …Run Code Online (Sandbox Code Playgroud) 我正在开发一个我想要使用Google Maps API的应用.
问题是与Google Maps API服务器的连接不稳定.有时它没关系,但有时候因为我在中国而受阻.
我提出的解决方案是通过反向代理生成所有Google Maps API请求.我可以在美国或香港设置服务器作为反向代理服务器,与Google地图服务器保持稳定的连接.
然后,我必须更改我的应用中所有Google Maps API的网址,以指向我的反向代理,代理将proxy_pass所有请求发送到Google地图服务器.
我有几个问题:
我将如何实现客户端库?我需要改变它们吗?如果是这样,我是否可以下载Google Maps JavaScript API文件并将其中的网址更改为我的代理服务器的域名?
我将如何使用Android和iPhone应用程序?我不确定Android和iPhone SDK是否会使用http协议发出请求.如果是,我如何用我的代理服务器的域名替换API的域名?
我想也许有一种方法可以捕获我的应用程序中发出的所有http请求并在发送之前对其进行修改但是谷歌搜索了一段时间后我发现它很难做到.
那么Android和iPhone应用程序可以做到这一点吗?或者有更好的方法来实现它与Web应用程序?
我也想知道这样做是否值得付出努力,因为解决方案看起来相当复杂,并且使用Google Maps API并不是必需的,因为在我们国家有替代它.我更喜欢谷歌地图API,因为它的API风格整洁,地图更漂亮.
如今,运行Perl Web应用程序的一个非常流行的选择似乎是nginx webserver代理对FastCGI守护程序或PSGI启用的Web服务器(例如Starman)的请求.
关于为什么一般会这样做会有很多问题(例如为什么在Catalyst/Plack/Starman中使用nginx?)并且答案似乎适用于这两种情况(例如,允许nginx提供静态内容,轻松重启应用程序服务器,负载均衡等)
但是,我对使用FastCGI与反向代理方法的优缺点特别感兴趣.似乎Starman被广泛认为是最快和最好的Perl PSGI应用程序/网络服务器,我很难看到使用FastCGI的任何优势.这两种方法似乎都支持:
同样,任一选项的nginx配置都非常相似.
那你为什么选择一个呢?
假设我们有几个相同的节点,它们是某些n层服务的应用服务器.假设我们使用Apache ZooKeeper来保留我们分布式应用程序的所有配置.另外,我们在此应用程序前面有一个nginx作为负载均衡器和反向代理.
因此,假设我们执行仅在node1上更改数据的命令,并且在某段时间内,node2与node1不同.我们希望代理将所有特殊请求(需要特定数据)重定向到node1,直到所有信息都迁移到node2并且node2与node1具有相同的数据.
有没有办法让nginx(或其他代理)从Apache ZooKeeper读取其配置?或更广泛的:有没有办法有效地切换代理配置?当然,它应该在没有(或最小)整个系统的停机时间内完成 - 因此重新启动nginx不是选项.
我正在尝试缓存静态内容,这些内容基本上位于虚拟服务器配置中的下面路径中.由于某种原因,文件未被缓存.我在缓存目录中看到了几个文件夹和文件,但它总是像20mb那样不高不低.如果它是缓存图像,例如将占用至少500mb的空间.
这是nginx.conf缓存部分:
** nginx.conf **
proxy_cache_path /usr/share/nginx/www/cache levels=1:2 keys_zone=static$
proxy_temp_path /usr/share/nginx/www/tmp;
proxy_read_timeout 300s;
Run Code Online (Sandbox Code Playgroud)
这是默认的虚拟服务器.
**sites-available/default**
server {
listen 80;
root /usr/share/nginx/www;
server_name myserver;
access_log /var/log/nginx/myserver.log main;
error_log /var/log/nginx/error.log;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
location ~* ^/(thumbs|images|css|js|pubimg)/(.*)$ {
proxy_pass http://backend;
proxy_cache static;
proxy_cache_min_uses 1;
proxy_cache_valid 200 301 302 120m;
proxy_cache_valid 404 1m;
expires max;
}
location / {
proxy_pass http://backend;
}
}
Run Code Online (Sandbox Code Playgroud) 我对如何解决这个问题有点困惑。我对运行 Apache2 的服务器进行了发行版升级。
自从升级之后就没有用了。我运行了配置测试,下面是错误。我在之前版本的 Ubuntu (21.10) 上的配置没有任何问题
$ apache2ctl configtest
apache2: Syntax error on line 146 of /etc/apache2/apache2.conf: Syntax error on line 3 of /etc/apache2/mods-enabled/php8.0.load: Cannot load /usr/lib/apache2/modules/libphp8.0.so into server: /usr/lib/apache2/modules/libphp8.0.so: cannot open shared object file: No such file or directory
Action 'configtest' failed.
The Apache error log may have more information.
Run Code Online (Sandbox Code Playgroud)
有什么想法从哪里开始吗?我对 Apache 还相当缺乏经验。
我们的nginx前端后面有几个后端.
是否有可能拦截这些后端发送的301/302重定向并让nginx处理它们?
我们独自在于:
error_page 302 = @target;
Run Code Online (Sandbox Code Playgroud)
但我怀疑301/302重定向可以像404等一样处理...我的意思是,error_page可能不适用于200等错误代码?
总结一下:
我们的后端偶尔发回301/302s.我们想让nginx拦截这些,并将它们重写到另一个位置块,在那里我们可以用它们做任何其他的事情.
可能?
谢谢!
redirect reverse-proxy nginx http-status-code-301 http-status-code-302
我发现这篇关于如何作为单独的代理应用使用的博客文章Rack::Proxy.本文解释了他如何使用端口上的应用程序Rack::Proxy代理请求和http://localhost:3000端口上的应用程序3001请求.我想做同样的事情,但我不想创建一个单独的代理应用程序.相反,我希望我的主Rails应用程序将请求代理到另一个应用程序.http://localhost:3000/api3002/blog
博客文章:http://livsey.org/blog/2012/02/23/using-rack-proxy-to-serve-multiple-rails-apps-from-the-same-domain-and-port/