nginx 的新手。玩了2天,不知道如何解决这个问题:
我有一堆虚拟机在一个盒子里运行,这个盒子显然在我的路由器后面,其中一个虚拟机正在运行 nginx(我的反向代理)并设置为 DMZ。
我已经在该 VM 上正确安装了 SSL 证书,现在我希望所有传入流量都根据其路径进行定向,例如:
domain.com/service1->192.168.1.101
domain.com/service2->192.168.1.102
等等。想法是让 nginx 作为 SSL 层工作,而 nginx 通过 HTTP 或任何未加密的协议与其他 VM 对话。然后当然当 nginx 与客户端对话时,消息应该被加密。
我已经部分工作了。如果我通过 HTTP 访问,除了未加密之外,一切都很好,但是如果我通过 HTTPS 访问,则网页会损坏,并且出现此类错误:Mixed Content: The page at 'https://domain.com/service1' was loaded over HTTPS, but requested an insecure stylesheet 'http://domain.com/service1/blahblah.css'. This request has been blocked; the content must be served over HTTPS.
我也收到了这样的警告: The page at 'https://domain.com/service1/' was loaded over HTTPS, but is submitting data to an insecure location at 'http://domain.com/service1/': this content should …
这个 nginx 实例的目的是让 GitLab 和 OpenWRT Luci 通过反向代理重定向。它已经在其他几个网站上工作,所有网站都有一个基本网址,似乎可以解决这个问题。
示例位置的相关 nginx 配置是;
location /gitlab/ {
proxy_pass http://127.0.0.1:9000/;
proxy_redirect default;
}
Run Code Online (Sandbox Code Playgroud)
有一些标头代理配置选项应用于此位置。
# Timeout if the real server is dead
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
# Basic Proxy Config
proxy_set_header Host $host:$server_port;
proxy_set_header Origin $scheme://$host:$server_port;
proxy_set_header Connection $http_connection;
proxy_set_header Cookie $http_cookie;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header X-Forwarded-Protocol $scheme;
proxy_set_header X-Scheme $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header …Run Code Online (Sandbox Code Playgroud) 我正在尝试做一些在我看来很简单的事情,但我一定是愚蠢的或错过了一些非常明显的事情,因为我无法弄清楚。
我想访问在我的服务器上运行的多个 Web 应用程序,每个应用程序都有一个唯一的前缀:
http://mywebserver/app1 -> localhost:9001
http://mywebserver/app2 -> localhost:9002
...
Run Code Online (Sandbox Code Playgroud)
据我了解,我需要将 Nginx 配置为反向代理,所以我这样做了:
server {
listen 80;
server_name mywebserver;
location /app1{
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://127.0.0.1:9001/;
}
...
}
Run Code Online (Sandbox Code Playgroud)
此配置允许我访问应用程序的主页http://mywebserver/app1,但未加载静态内容。
当我打开我的浏览器的控制台上,我可以看到它正试图从获得的资源http://mywebserver/static/custom/index.js,而不是像http://mywebserver/app1/static/custom/index.js。
我尝试root在 location 块中添加一个指令来为静态提供服务,但由于静态内容请求是 on/而不是 on ,因此未将其考虑在内/app1。
如何解决这个问题?有什么明显的我遗漏了还是我完全误解了反向代理的概念?
谢谢你。
nginx web-applications reverse-proxy static-content static-files
使用 Nginx 作为反向代理,如何在 cookie 中添加 samesite=strict 或 samesite=lax?
我是 nginx 的新手,但我需要根据子域创建一些代理规则以重定向到另一个 IP 和端口。
这是我的情况:
My domain.com has IP y.y.y.y and accepts requests on port 80
My subdomains are:
- admin.domain.com -> I need to proxy to x.x.x.x:3434
- user.domain.com -> I need to proxy tox.x.x.x:3435
- vendor.domain.com -> I need to proxy to x.x.x.x:3436
Run Code Online (Sandbox Code Playgroud)
所有子域都映射到y.y.y.y但在 nginx 中我需要代理到x.x.x.x:ZZZ(ZZZ 是其他服务的特定端口)。
我正在尝试这个例子但没有成功:https : //rainbow-six3.com/plesknginx/
有人可以提供一个示例,如何在 nginx 上配置它?
嗨,这是一种情况,我在公司数据中心有一台用于项目的服务器。我在端口 22 上可以通过 SSH 访问这台机器。在这台服务器上运行着一些虚拟机,然后在许多其他操作系统正在运行的每件事的背后。现在,由于我在数据中心防火墙后面,我的主管问我是否可以做一些事情,让互联网上的许多人直接访问这些虚拟机。我知道如果我被允许在 22 以外的端口上获得流量,那么我可以进行端口转发。但是由于我不允许这样做,所以在这种情况下可以解决什么问题。想要连接的人可能完全是白痴。他们可能只是在他们的机器上打开腻子就很高兴,甚至可能是 filezilla。
我手上没有防火墙,也没有打开 22 以外的任何端口,事实上,即使我要求他们也不允许打开。2 次 SSH 不是我的主管想要的东西。
我有一个 IIS 6.0 Web 服务器暴露在互联网上,它不能可靠地执行 Gzipping。我知道它已经过时了,但这就是我必须为这个实例工作的全部内容。
我想要做的是将 Nginx(或类似的)作为反向代理和缓存服务器放在 IIS 前面,以加快网站速度。但是,我不确定是否可以将 nginx 服务器从自身 gzip 压缩到 Web 浏览器。如果 IIS 将 Gzipped 请求传递回 nginx,它们就会很好地返回到浏览器。
gzip on;
gzip_min_length 1000;
gzip_buffers 4 8k;
gzip_http_version 1.0;
gzip_disable "msie6";
gzip_types text/plain text/css;
gzip_vary on;
location / {
proxy_set_header x-real-IP $remote_addr;
proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
proxy_set_header host $host;
proxy_pass http://192.168.5.37;
}
Run Code Online (Sandbox Code Playgroud)
HTTP 请求 (/css/components.css)
GET /css/components.css HTTP/1.1
Host: www.mydomain.co.uk
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Accept: text/css,*/*;q=0.1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_0) AppleWebKit/537.36 (KHTML, like Gecko) …Run Code Online (Sandbox Code Playgroud) 我的环境有用户请求通过多个系统:
[客户端] --> [ELB] ---> [nginx] --> [网络]
(ELB = AWS 弹性负载均衡器)
多亏了这个答案,我让 nginx 确定并将正确的客户端 IP 地址传递给带有X-Forwarded-For和X-Real_IP标头的上游服务器(Web)。相关的 nginx 配置:
real_ip_header X-Forwarded-For;
set_real_ip_from 10.0.0.0/8;
real_ip_recursive on;
proxy_set_header X-Real-IP $remote_addr;
Run Code Online (Sandbox Code Playgroud)
我的问题是,nginx 中的 Real IP 模块用$remote_addr其X-Forwarded-For计算结果替换了现有变量。这为我提供了原始客户端 IP,但我丢失了实际将请求发送到代理(即 ELB)的系统的 IP 地址。
总的来说,拥有客户端 IP 对我来说更重要,但我希望能够记录完整的请求链,以便我可以了解(和调试)流量是如何流动的。目前,我只能让 nginx 记录客户端 IP、它自己的 IP 和上游服务器 IP。我也希望能够记录 ELB IP。
自从我开始在反向代理(Apache2 的 mod_jk)后面使用应用程序后,我注意到有些页面无法加载(如果没有反向代理设置,它们会加载)。
这是一个微妙的错误,我必须检查才能找到它,这要归功于谷歌浏览器:无法加载资源:net::ERR_CONNECTION_RESET。
简单地说,一个 JavaScript 文件将被部分加载(从 ~50KB 中加载了 ~12KB)。
我认为 Apache2、mod_jk、AJP 或 Jetty 有问题。
但后来我进行了一项调查,在那里我将使用不同的浏览器和不同的网络。
结论: 此错误 (ERR_CONNECTION_RESET) 仅在我使用具有静态IP 的网络时发生。
我在一台路由器上降低了安全级别,但徒劳无功。
具有静态 IP 的网络是否配备了更高级别的安全性?
如何克服这个问题?
这是一个僵局,因为反向代理主要是为了利用我们卖点的静态 IP 地址来提高安全级别。
reverse-proxy ×10
nginx ×7
ajp ×1
amazon-elb ×1
apache-2.4 ×1
cookies ×1
domain ×1
hostname ×1
http ×1
http-headers ×1
logging ×1
mod-jk ×1
proxy ×1
rewrite ×1
ssh ×1
ssh-tunnel ×1
static-files ×1
static-ip ×1
subdomain ×1