有没有人知道如何在反向代理模式下告诉Apache拦截或捕获来自后端服务器的302(或30x)响应并在内部重定向而不向客户端发送30x响应?最终,响应被重定向到的后端服务器将无法从外部访问(或未在Apache conf中列出).
我的情况:
我有web_server_A和web_server_B正在侦听端口6666和7777.这些端口无法从外部访问,但可以从内部访问.
我最终可以更改web_server_A的行为,但不能更改web_server_B的行为.
Apache正在侦听端口80/443,可从外部访问,并充当反向代理,将发送到web_server_ {A,B} .example.com的请求发送到web_server_ {A,B}
客户端向Apache请求web_server_A.example.com/foo.Apache将请求代理到web_server_A,后者生成一些内容,然后将指向web_server_B.example.com/bar/secret_token的HTTP/302响应发送回Apache.Apache向客户端发回302响应,然后向Apache发送web_server_B.example.com/bar/secret_token的HTTP请求.Apache将请求代理到web_server_B,后者回复了一些内容(通常会发回一些大文件).
我的问题:
我不希望客户端知道url web_server_B.example.com/bar/secret_token,最终我不希望从外部访问web_server_B.
web_server_A可以向web_server_B发出请求,然后从web_server_B发回答案,而不发出302回复.但是,web_server_B的答案可能需要一些时间,可能会非常大,而web_server_A不应该在任何请求上花费太多时间(它无法处理大文件).
所以我想到了一个"302捕手"功能,如果存在的话会很好,但到目前为止还没有在网上为如何做到这一点提供任何资金.任何的想法?
我目前正在开发一个项目,该项目需要我们当前的 ASP.NET MVC5 Web 应用程序之一位于客户端将控制的 NGINX 反向代理后面。
我是 NGINX 的新手,所以缺乏知识。
反向代理将放置在子路径中。(下面的例子)
http://localhost:9999/foo/bar/
然后,这将代理到 MVC5 应用程序的根(端口 9998),我已在本地设置了 NGINX 以测试该站点是否按预期工作。我们使用资源的绝对路径(托管在内部 CDN 中),因此所有这些都按预期加载。
我的问题- 反向代理工作正常并显示应用程序的根页面。当点击使用 this.RedirectToAction() 或 @html.ActionLink() 等创建的任何控制器方法/页面链接时,问题开始出现。
MVC 应用程序没有意识到它正在反向代理后面运行,并从其派生 URL 中删除了该子路径。
所以重定向到家庭控制器看起来像
代替 :
http://localhost:9999/foo/bar/home
有人有什么想法可以抵消这个吗?我可以看到 .NET core 有一个解决方法,但看不到 MVC5 的任何内容。我可以使用 this.Redirect() 并指定绝对路径,但应用程序很大,并且在没有反向代理的其他场景中使用。
这个问题可以通过我的 NGINX 配置来解决吗?我在下面包含了我的配置:
#user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 9999;
server_name localhost;
location /foo/bar/ {
rewrite ^/foo/bar/(.*)$ /$1 break;
proxy_pass …Run Code Online (Sandbox Code Playgroud) 我配置了 apache proxypass,它可以工作,但无法加载图像、javascript、CSS 等...我想 proxypass 到另一台服务器,而不是本地主机。以下是我的配置。
<VirtualHost *:80>
ServerName app.server.com
DocumentRoot /var/www/html/subdomain
RewriteEngine on
ProxyRequests Off
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyPass /apm http://192.168.1.102:9999/
ProxyPassReverse /apm http://192.168.1.102:9999/
</virtualHost>
Run Code Online (Sandbox Code Playgroud) 我正在尝试设置一个 nginx,它可以根据域名将加密的 tcp 流传递到另一个应用程序,或者充当提供自己证书的反向代理。
\n\n我想归档以下情况:
\n\n https://app1.app.com \xe2\x94\x80\xe2\x94\x80\xe2\x96\xba pass-through encrypted tcp to :10001\n https://app2.app.com \xe2\x94\x80\xe2\x94\x80\xe2\x96\xba pass-through encrypted tcp to :10002\n https://app3.app.com \xe2\x94\x80\xe2\x94\x80\xe2\x96\xba serve ssl, reverse-proxy to http://ip:10003\nRun Code Online (Sandbox Code Playgroud)\n\n因此,在不破坏应用程序 1 和 2 的加密连接的情况下,nginx 应该转发 tcp 数据包。证书将由申请本身提供。主机名检测与 ssl_preread 一起使用。
\n\n但应用程序 3 只能通过 http 访问,因此 nginx 应该提供证书本身并代理从特定主机名app3.app.com到未加密后端的所有内容。
我有一个适用于前两种情况的工作配置,并且可以设置第三种情况,但无法弄清楚如何将这两种情况组合到一个 nginx 配置中。
\n\n到目前为止我所拥有的:
\n\nuser www-data;\nworker_processes 1;\n\nload_module /usr/lib/nginx/modules/ngx_stream_module.so;\n\nhttp {\n include /etc/nginx/mime.types;\n default_type application/octet-stream;\n\n log_format main \'$remote_addr - $remote_user [$time_local] "$request" \'\n \'$status $body_bytes_sent "$http_referer" \'\n \'"$http_user_agent" "$http_x_forwarded_for"\';\n\n access_log …Run Code Online (Sandbox Code Playgroud) 我有一个用于在 nginx 上运行的角度应用程序的 docker 容器,名为“website”。我想从其他名为“test.nginx”的 nginx 反向代理容器访问此容器。但我不知道如何配置 nginx.conf 进行反向代理。
首先,我正在为 Angular 应用程序创建 docker 映像。Dockerfile:
FROM nginx:alpine
COPY default.conf /etc/nginx/conf.d/default.conf
COPY angular /usr/share/nginx/html
Run Code Online (Sandbox Code Playgroud)
这里的角度文件夹包含角度构建文件(index.html,main.js,runtime.js ...)
默认.conf:
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
Run Code Online (Sandbox Code Playgroud)
docker-compose.yml
version: '3.4'
services:
nginx:
image: nginx:latest
container_name: test.nginx
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
ports:
- 2020:80
environment:
- NETWORK_ACCESS=internal
website:
image: website
container_name: website
restart: on-failure
ports: …Run Code Online (Sandbox Code Playgroud) 我正在尝试结合使用本指南和此处找到的代码来设置 traefik 。
我正在docker-compose与 Unraid 一起使用,到目前为止我有以下代码:
traefik.toml:
debug = false
logLevel = "ERROR"
defaultEntryPoints = ["https","http"]
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.http.redirect]
entryPoint = "https"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]
[retry]
[acme]
email = "user@domain.com"
storage = "acme.json"
entryPoint = "https"
#OnHostRule = true
#onDemand = true
[acme.dnsChallenge]
provider = "cloudflare"
[[acme.domains]]
main = "domain.name"
[[acme.domains]]
main = "*.domain.name"
Run Code Online (Sandbox Code Playgroud)
docker-compose.yml:
services:
traefik:
image: traefik:latest
command: --web --docker --docker.watch --docker.domain=${DOMAIN} \
--docker.exposedbydefault=false --acme.domains=${DOMAIN}
container_name: …Run Code Online (Sandbox Code Playgroud) 在我的 gitea 服务器上,我通常通过 ssh 本地端口转发访问它;并且无法从外部访问它,因为我将其绑定到本地主机地址。
我通过“本地端口转发”访问它http://127.0.0.1:8080,它认为它是从http://127.0.0.1:3000;访问的。所以某些功能(例如维基中的预览和问题不起作用(但是您可以保存它们,只是不预览它们);无论如何它配置错误,请参见下文,我想更改,以便Gitea Base URL随时服务器当前写入http://127.0.0.1:3000它将http://127.0.0.1:8080改为写入(但也就是说,如果它仍然在端口上运行,那就太好了3000):
哪一行gitea.ini改变了这个功能?或者更像是我需要在它前面放置一个反向代理来为我重写 URL 的情况?
localhost:3000当我使用运行开发服务器时npm run start,服务器按预期工作。我正在使用react-scripts,我还没有弹出react应用程序。
我想做的是在反向代理后面设置开发服务器。因此localhost:5572/author/name/将指向运行在localhost:3000.
设置工作正常,index.html 已加载。但当开发服务器运行在 时"/",页面会尝试将脚本加载为"<script src="/static/js/bundle.js"></script>". 因此,它期望 URL 为localhost:5572/static/js/bundle.js. 但反向代理正在提供相同的文件localhost:5572/author/name/static/js/bundle.js
在 package.json 中,我指定了
{
...
"homepage": "./",
...
}
Run Code Online (Sandbox Code Playgroud)
所以我的生产版本有相对路径,但开发版本没有。
有没有办法使用相对路径而不是绝对路径?或者我可以使用不同的解决方案。
谢谢。
k8s 入口控制器不会将证书传递给上游 https 服务。
使用 nginx 我可以实现这样的目标
location /upstream {
proxy_pass https://backend.example.com;
proxy_ssl_certificate /etc/nginx/client.pem;
proxy_ssl_certificate_key /etc/nginx/client.key;
}
Run Code Online (Sandbox Code Playgroud)
我在这里错过了什么吗?我当前的配置看起来像这样。我不希望来自客户端的 pass ssl 在此终止。
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: backend
namespace: default
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: "/$1"
nginx.ingress.kubernetes.io/backend-protocol: HTTPS
nginx.ingress.kubernetes.io/secure-backends: "true"
nginx.ingress.kubernetes.io/proxy-ssl-secret: "proxy-ca-secret"
nginx.ingress.kubernetes.io/proxy-ssl-name: "backend.example.com"
spec:
rules:
- http:
paths:
- path: /(api/auth/.*)
backend:
serviceName: auth
servicePort: 8080
Run Code Online (Sandbox Code Playgroud)
日志显示
SSL_do_handshake() failed (SSL: error:14094412:SSL routines:ssl3_read_bytes:sslv3 alert bad certificate:SSL alert number 42) while SSL handshaking to upstream
Run Code Online (Sandbox Code Playgroud)
我使用 openssl 证书验证了 base64 证书,看起来不错。提前致谢!
reverse-proxy nginx kubernetes nginx-reverse-proxy kubernetes-ingress
我想设置一个带有反向代理的 websocket 服务器。为此,我使用 python 中的简单 websocket 服务器和 nginx 反向代理创建了一个 docker-compose。
设置:
docker-compose.yml:
version: '2.4'
services:
wsserver:
restart: always
ports:
- 8765:8765
build:
context: ./server
dockerfile: Dockerfile
ngproxy:
image: nginx
ports:
- 8020:80
- 5000:5000
restart: always
depends_on:
- wsserver
volumes:
- ./nginx/nginx.conf:/etc/nginx/conf.conf
Run Code Online (Sandbox Code Playgroud)
nginx.conf:
http {
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream websocket {
server wsserver:8765;
}
server {
listen 5000;
location / {
proxy_pass http://websocket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host; …Run Code Online (Sandbox Code Playgroud)