我正在尝试使用反向代理添加 SSL 证书在我的域的子目录上提供自托管的 sourcegraph 服务器。
目标是让http://example.org/source为 sourcegraph 服务器提供服务
我的重写和反向代理如下所示:
location /source {
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-Scheme $scheme;
rewrite ^/source/?(.*) /$1 break;
proxy_pass http://localhost:8108;
}
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是,在调用http://example.org/source 时,我被重定向到http://example.org/sign-in?returnTo=%2F
有没有办法将 sourcegraph 的响应重写到正确的子目录?
另外,我可以在哪里调试重写指令?我想遵循它所做的更改以更好地理解它。
- 编辑:
我知道我的方法使用重写可能是错误的,我现在正在尝试 sub_filter 模块。
我使用 tcpdump 捕获了 sourcegraph 的响应并使用 wireshark 进行了分析,所以我在:
GET /sourcegraph/ HTTP/1.0
Host: 127.0.0.1:8108
Connection: close
Upgrade-Insecure-Requests: 1
DNT: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8 …Run Code Online (Sandbox Code Playgroud) 我有以下 nginx.conf
location /monitoring/prometheus/ {
resolver 172.20.0.10 valid=5s;
set $prometheusUrl http://prometheus.monitoring.svc.cluster.local:9090/;
proxy_set_header Accept-Encoding "";
proxy_pass $prometheusUrl;
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;
sub_filter_types text/html;
sub_filter_once off;
sub_filter '="/' '="/monitoring/prometheus/';
sub_filter 'var PATH_PREFIX = "";' 'var PATH_PREFIX = "/monitoring/prometheus";';
rewrite ^/monitoring/prometheus/?$ /monitoring/prometheus/graph redirect;
rewrite ^/monitoring/prometheus/(.*)$ /$1 break;
}
Run Code Online (Sandbox Code Playgroud)
当我导航到https://myHost/monitoring/prometheus/graph 时,我被重定向到 /graph ( https://myHost/graph )
当我不使用变量并将 url 直接放置到 proxy_pass 时,一切都按预期工作。我可以导航到https://myHost/monitoring/prometheus/graph并查看 prometheus。
location /monitoring/prometheus/ {
resolver 172.20.0.10 valid=5s;
proxy_set_header Accept-Encoding "";
proxy_pass http://prometheus.monitoring.svc.cluster.local:9090/; …Run Code Online (Sandbox Code Playgroud) 我正在构建一个用于上传大文件(数 GB)的反向代理,因此想要使用不缓冲整个文件的流模型。大缓冲区会引入延迟,更重要的是,它们可能会导致内存不足错误。
我的客户端类包含
@Autowired private RestTemplate restTemplate;
@Bean
public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
int REST_TEMPLATE_MODE = 1; // 1=streams, 2=streams, 3=buffers
return
REST_TEMPLATE_MODE == 1 ? new RestTemplate() :
REST_TEMPLATE_MODE == 2 ? (new RestTemplateBuilder()).build() :
REST_TEMPLATE_MODE == 3 ? restTemplateBuilder.build() : null;
}
Run Code Online (Sandbox Code Playgroud)
和
public void upload_via_streaming(InputStream inputStream, String originalname) {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
requestFactory.setBufferRequestBody(false);
restTemplate.setRequestFactory(requestFactory);
InputStreamResource inputStreamResource = new InputStreamResource(inputStream) {
@Override public String getFilename() { return originalname; }
@Override public long contentLength() { return -1; …Run Code Online (Sandbox Code Playgroud) 我试图让 Nexus3 在 Nginx 后面运行。
Nginx 用作反向代理和 SSL 终止。通过 Nginx 访问 /nexus 路径时,我收到多个错误,例如“由于无法访问服务器而导致操作失败”和“无法检测到您连接到哪个节点”。在不通过 Nginx 的情况下访问 Nexus UI 效果很好,这让我认为错误出在 Nginx 上。
NginX 配置文件
location /nexus {
proxy_pass http://localhost:8081/nexus/;
proxy_set_header Host $host:$server_port;
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 https;
resolver 8.8.8.8 8.8.4.4 ipv6=off;
}
Run Code Online (Sandbox Code Playgroud) 我正在运行带有以下docker-compose.yml文件的私有 docker -registry v2 :
registry:
restart: always
image: registry:2
ports:
- 5000:5000
environment:
REGISTRY_HTTP_TLS_CERTIFICATE: /certs/server-cert.pem
REGISTRY_HTTP_TLS_KEY: /certs/server-key.pem
REGISTRY_AUTH: htpasswd
REGISTRY_AUTH_HTPASSWD_PATH: /auth/htpasswd
REGISTRY_AUTH_HTPASSWD_REALM: Registry Realm
volumes:
- /data/docker-registry:/var/lib/registry
- /certs/docker-registry:/certs
- /auth/docker-registry:/auth
Run Code Online (Sandbox Code Playgroud)
我可以在http://localhost:5000本地登录(SSH,Jenkins,...)。
现在我想用 Apache httpd 公开这个注册表。我在 CentOS 7 上运行以下版本的 httpd:
[root@dev-machine conf.d]# httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built: Jun 27 2018 13:48:59
Run Code Online (Sandbox Code Playgroud)
这是我的vhosts.conf:
<VirtualHost *:443>
ServerName dev-machine.com
ServerAlias www.dev-machine.com
ErrorLog logs/dev-machine.com-error_log
CustomLog logs/dev-machine.com-access_log common
SSLEngine on
SSLCertificateFile /certs/docker-registry/server-cert.pem
SSLCertificateKeyFile /certs/docker-registry/server-key.pem …Run Code Online (Sandbox Code Playgroud) 在使用特使代理进行外部身份验证后,是否有任何方法可以删除上游的标头?我们计划为我们的内部 API 网关迁移到 Envoy 代理,但现在这是一个障碍。
例如:外部认证服务获取请求并处理认证头,万一验证失败,它会抛出401。但如果成功,我想阻止auth头进入上游。
根据文档Ext Auth:
成功的检查允许授权服务在将原始请求分派到上游之前添加或覆盖来自原始请求的标头。这是通过配置授权响应中的哪些标头应该发送到上游来完成的。请参阅下面的 allowed_authorization_headers。
没有提到我是否可以完全删除上游的标题。
我可以选择覆盖标头,但这会导致上游服务器上的标头冲突。所以这不是一个可能的解决方案。
我怎样才能做到这一点?
最近,我们 cookie 中的数据量变大了,所有通过 nginx 的请求都开始被拒绝,并出现 431 错误响应。
我尝试增加 large_client_header_buffers 和 client_header_buffer_size 无济于事。这是我正在使用的主要 nginx.conf 示例:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
large_client_header_buffers 4 64k;
client_header_buffer_size 8k;
include /etc/nginx/conf.d/*.conf;
}
Run Code Online (Sandbox Code Playgroud)
对于特定的服务器块:
server {
listen 443 ssl;
server_name staging1.acme.services;
ssl_certificate /certs/acme.services/fullchain.pem;
ssl_certificate_key /certs/acme.services/privkey.pem;
ssl_session_cache …Run Code Online (Sandbox Code Playgroud) 如果我只是在后台发送 ajax 请求,然后用户离开/关闭页面,然后从 nodejs 脚本获得进程完成的确认,那么反向代理后面的 nodejs 进程会发生什么?
例如,它是继续工作并完成异步循环,还是只是终止并在错误处理程序处停止?中途留下数据?
我是 Traefik v2.1.4 的初学者。我在 docker 容器中使用。我正在尝试设置静态路由。我找到了一些使用 toml 配置文件的示例。
[providers]
[providers.file]
[http]
[http.routers]
[http.routers.netdata]
rule = "Host(`netdata.my-domain.com`)"
service = "netdata"
entrypoint=["http"]
[http.services]
[http.services.netdata.loadbalancer]
[[http.services.netdata.loadbalancer.servers]]
url = "https://192.168.0.2:19999"
Run Code Online (Sandbox Code Playgroud)
按照这个例子,我想将它转换为我的 docker-compose 的 docker 标签。
我的 docker-compose 文件:
version: "3.7"
services:
traefik:
image: traefik:v2.1.4
container_name: traefik
restart: always
command:
- "--log.level=DEBUG"
- "--api.insecure=false"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:80"
- "--entrypoints.websecure.address=:443"
- "--certificatesresolvers.letsresolver.acme.tlschallenge=true"
- "--certificatesresolvers.letsresolver.acme.email=my-email@domain.com"
- "--certificatesresolvers.letsresolver.acme.storage=/letsencrypt/acme.json"
labels:
- "traefik.enable=true"
# middleware redirect
- "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
# global redirect to https
- "traefik.http.routers.redirs.rule=hostregexp(`{host:.+}`)"
- "traefik.http.routers.redirs.entrypoints=web" …Run Code Online (Sandbox Code Playgroud) 所以我试图使用 NGINX 作为 2 个反应应用程序和 1 个节点 js api 的反向代理。每个都在单独的 docker 容器中。
例如,
本地主机 -> 导致一个反应应用程序
localhost/admin -> 导致另一个反应应用程序
localhost/api/getProducts -> 指向 api 的 /getProducts 端点
第一个示例和第二个示例都按预期工作。没有问题。这是我在配置时遇到问题的第二个示例。它应该只是导致一个内置于 React 的仪表板应用程序,但我得到的只是一个白屏(与第一个 React 应用程序具有相同的图标)。
这是我的 nginx 配置文件
upstream api {
least_conn;
server api:8080 max_fails=3 fail_timeout=30s;
}
upstream app {
least_conn;
server app:3000 max_fails=3 fail_timeout=30s;
}
upstream adminapp {
least_conn;
server adminapp:3001 max_fails=3 fail_timeout=30s;
}
server {
listen 80;
if ($request_method = 'OPTIONS') {
return 200;
}
# To allow POST on static pages …Run Code Online (Sandbox Code Playgroud) reverse-proxy ×10
nginx ×5
docker ×2
apache ×1
apache2.4 ×1
envoyproxy ×1
forwarding ×1
javascript ×1
kubernetes ×1
nexus3 ×1
node.js ×1
prometheus ×1
proxypass ×1
reactjs ×1
resttemplate ×1
sourcegraph ×1
spring ×1
spring-boot ×1
streaming ×1
traefik ×1