标签: nginx-reverse-proxy

Nginx 代理管理器服务器的 SSL 可访问性测试失败

我的域名来自domains.google.com. 假设它是mydomainname.com

我将 DNS 设置为我想要的 IP 地址。在我的路由器上,我将端口转发80到我的计算机80443我的计算机的443. 为了确认它是公开可用的,我使用了不同的连接和设备,并且可以mydomainname.com毫无问题地访问。

然后我使用了他们网站docker-compose.yml中描述的文件。

当前latest指向v2.9.18

version: '3'

services:
  app:
    image: 'jc21/nginx-proxy-manager:latest'
    restart: unless-stopped
    ports:
      - '80:80'
      - '443:443'
      - '81:81'
    volumes:
      - ./data/:/data
      - ./letsencrypt:/etc/letsencrypt
Run Code Online (Sandbox Code Playgroud)

现在,在 SSL 证书选项卡上,添加 SSL 证书时,测试服务器可访问性始终失败,并出现以下错误:

mydomainname.com: There is no server available at this domain.
Please make sure your domain exists and points to the IP where your NPM
instance is running …
Run Code Online (Sandbox Code Playgroud)

ssl nginx docker-compose lets-encrypt nginx-reverse-proxy

5
推荐指数
0
解决办法
3013
查看次数

将“https://files.mydomain.com/files”重写为“https://files.mydomain.com”

目前,我可以访问: https://files.mydomain.com/files。即使我去https://files.mydomain.com,它也会自动重定向到https://files.mydomain.com/files成功。

相反,我希望 NGINX 自动重写https://files.mydomain.com/files->https://files.mydomain.com

我当前的 NGINX 代码:

http {

    server {
        
            listen       80;
            server_name  localhost;
            return 301 https://$host$request_uri;
    }

    server {

            listen       80;
            server_name  files.mydomain.com;
            location / {
                return 301 https://files.mydomain.com$request_uri;
        }
    }

    server {
            listen 443 ssl http2; 
            listen [::]:443 ssl http2;
            server_name  files.mydomain.com;
            client_max_body_size 0;
            location / {
                return 301 https://$host/files;
            } 
            location /files {
                proxy_pass http://localhost:89;
            }
    }

    #Root Domain
    server {
            listen 443 ssl http2; 
            listen [::]:443 …
Run Code Online (Sandbox Code Playgroud)

nginx nginx-reverse-proxy nginx-config

5
推荐指数
1
解决办法
250
查看次数

使用nginx反向代理部署K8S时ABP框架HttpApi.Host失败

我已经将ABP框架部署在Kubernetes集群中。

存在以下部署:

  • 雷迪斯
  • MSSql
  • 认证服务器
  • HttpApi.Host
  • Nginx 入口/反向代理带有 https 终止,集群内没有加密。

因此,AuthServer、HttpApi.Host 正在侦听端口 80 / http,而 nginx 正在侦听 https。配置/Helm 值如下:

use-forwarded-headers: "true"
use-proxy-protocol: "true"
use-gzip: "true"
Run Code Online (Sandbox Code Playgroud)

到目前为止一切顺利,部署后我可以进入 Swagger 并授权: 在此输入图像描述

通过检查 AuthServer 日志可以确认这一点:

[19:12:39 INF] CORS policy execution successful.
[19:12:39 INF] The request URI matched a server endpoint: Token.
[19:12:39 INF] The token request was successfully extracted: {
  "grant_type": "authorization_code",
  "code": "[redacted]",
  "client_id": "foobar_Swagger",
  "redirect_uri": "https://api.staging.foobar.io/swagger/oauth2-redirect.html"
}.
[19:12:39 INF] The token request was successfully validated.
Run Code Online (Sandbox Code Playgroud)

但是,现在我想使用 Swagger 来确保与端点的连接正常工作,因此我尝试第一个 GET 端点: 在此输入图像描述

如您所见,有 500 …

kubernetes openiddict nginx-reverse-proxy abp

5
推荐指数
1
解决办法
260
查看次数

如何代理从/传递到/index.html

我目前正在使用URL路径的JS项目上工作。现在,如果我使用example.com/进入我的网站,则JavaScript将无法工作,因为我实际上需要example.com/index.html

我已经在使用反向代理来代理传递给两个不同的Docker容器。所以我的想法是将请求传递给example.com/index.htmlexample.com/被调用。但是我不知道要实现这个目标的正则表达式的东西。

我的旧配置:

server {
listen       80;
server_name  example.com;

# allow large uploads of files - refer to nginx documentation
client_max_body_size 1G;

# optimize downloading files larger than 1G - refer to nginx doc 
before adjusting
#proxy_max_temp_file_size 2G;

location / {
    proxy_pass http://structure.example:80;
}

location /cdn {
    proxy_pass http://content.example:80;
}

error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   /usr/share/nginx/html;
}

}
Run Code Online (Sandbox Code Playgroud)

我尝试过的东西:

    server {
listen       80;
server_name  example.com;

# …
Run Code Online (Sandbox Code Playgroud)

nginx nginx-location nginx-reverse-proxy

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

使用 nginx 反向代理时,nodejs 中未收到自定义标头

我有和的NodeJS Nginx的运行我是API“API_KEY”在增派头及其在没有收到req.headersreq.get('api_key')在我的NodeJS有nginx的波纹管配置文件

server {
    listen 80;
    listen [::]:80 default_server ipv6only=on;
    server_name mysite.com;
    return 301 https://$host$request_uri;
 location / {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-NginX-Proxy true;
    proxy_pass http://localhost:9102/;
    proxy_set_header Host $http_host;
    proxy_set_header api_key $http_api_key; 
    #proxy_set_header api_key 'Some Value'; works 
    proxy_redirect off;
  }
}
Run Code Online (Sandbox Code Playgroud)

如果设置proxy_set_header api_key 'some value'它的值有效并且标题打印在控制台上但api_key会发生变化,这就是我使用的原因,$http_api_key以便api_key自定义标题中的任何内容在从其余客户端发送时被接收。我已经尝试了几个解决方案,proxy_set_header api_key $upstream_http_api_key;但没有帮助。我想接收从 nodejs 中的休息客户端发送的任何自定义标头。

reverse-proxy nginx http-headers node.js nginx-reverse-proxy

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

Nginx不会自动获取群中的dns更改

我通过docker swarm中的默认nginx配置(根据lets-nginx项目)通过lets-nginx运行nginx :

服务:

  ssl:
    image: smashwilson/lets-nginx
    networks:
      - backend
    environment:
      - EMAIL=sas@finestructure.co
      - DOMAIN=api.finestructure.co
      - UPSTREAM=api:5000
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - letsencrypt:/etc/letsencrypt
      - dhparam_cache:/cache

  api:
    image: registry.gitlab.com/project_name/image_name:0.1
    networks:
      - backend
    environment:
      - APP_SETTINGS=/api.cfg
    configs:
      - source: api_config
        target: /api.cfg
    command:
      - run
      - -w
      - tornado
      - -p
      - "5000"
Run Code Online (Sandbox Code Playgroud)

api是在群体覆盖网络的端口5000上运行的Flask应用backend

最初启动服务时,一切正常。但是,每当我api以使api容器在三个节点群中的节点之间移动的方式进行更新时,都nginx无法将流量路由到新容器。

我在nginx日志中看到,当新容器现在位于10.0.0.4上时,它会粘贴到旧的内部ip,例如10.0.0.2。

为了使nginx“看到”新IP,我需要重新启动nginx容器,或者重新启动docker exec它并kill -HUP进入nginx进程。

有没有更好的自动方法来使Nginx容器刷新其名称解析?

nginx docker docker-swarm nginx-reverse-proxy

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

基于referer的nginx条件路由

我需要根据 http 请求来源路由流量。我有两个环境,我们需要使用“$http_referer”将“/us-en”的每个http请求重定向到Environment1,其他人重定向到Environment2。

  1. 基于位置的重定向有效。
location ~ /us-en { 
    proxy_pass Environment1; 
    proxy_set_header Host Environment1; 
} 
Run Code Online (Sandbox Code Playgroud)
  1. 使用 '$http_referer' 下面的选项不起作用。请求您的建议。
if ($http_referer ~ ^https?://dev.xyz.com/us-en){ 
    rewrite ^/us-en(/*)$ HOME_PAGE$1 break; 
    proxy_pass Environment1; 
}
Error: nginx: [emerg] "proxy_pass" directive is not allowed here in /opt/nginx/conf/nginx.conf.
Run Code Online (Sandbox Code Playgroud)

注意:默认情况下,所有流量都进入 Environment2,因为存在上游配置。

nginx nginx-reverse-proxy nginx-config

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

Nginx HTTP未重定向到HTTPS 400错误请求“普通HTTP请求已发送到HTTPS端口”

我正在docker中运行Nginx。HTTPS工作正常,但是当我明确发出HTTP请求时,出现以下错误

400错误的请求普通的HTTP请求已发送到HTTPS端口

nginx.conf如下

worker_processes auto ;          
events {}

http {

include /etc/nginx/mime.types;

access_log /var/log/nginx/main.access.log;                                           

server {    
listen 80;                                                                                                       
location / {
    return 301 https://localhost:3000$request_uri; 
}

}

server {   
listen 443 ssl;                                                      
server_name  localhost:3000;                  
 root    /var/www/html; 

ssl_certificate         /etc/nginx/ssl/cert.pem; 
ssl_certificate_key     /etc/nginx/ssl/key.pem;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:DH+3DES:!ADH:!AECDH:!MD5;

location / {
try_files  $uri /index.html;        
}

}

}
Run Code Online (Sandbox Code Playgroud)

我使用这个容器运行

docker run -p 3000:443 -it -d --name nginxtest nginx-test
Run Code Online (Sandbox Code Playgroud)

并得到以下错误

docker文件如下

FROM nginx:latest
COPY ./build /var/www/html
COPY ./nginx.conf /etc/nginx/nginx.conf
COPY ./ssl /etc/nginx/ssl
EXPOSE …
Run Code Online (Sandbox Code Playgroud)

nginx docker nginx-reverse-proxy nginx-config

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

在 unbuntu 和 nginx 上托管多个 ASP NET Core 站点作为反向代理

我正在尝试在 Linux、Unbunt 18.04 上托管多个具有不同域的 ASP NET Core 站点,并使用 nginx 作为反向代理。

这些是步骤:

1) 在 /etc/nginx/sites-available 中创建新的 .conf 文件

2) 在 /var/www/ 中创建文件夹并在 .net 应用程序中上传

3) 为每个 .conf 文件创建新的 .service 文件

默认的 nginx .conf 没有改变。

.conf 文件如下所示:

server {
    listen        80;
    server_name   domain;
    location / {
        proxy_pass         http://localhost:5000;
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection keep-alive;
        proxy_set_header   Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
    }
}

Run Code Online (Sandbox Code Playgroud)

.service 文件如下所示:

[Unit]
Description=Event Registration Example

[Service]
WorkingDirectory=/var/www/example
ExecStart=/usr/bin/dotnet /var/www/example/example.dll
Restart=always
# Restart …
Run Code Online (Sandbox Code Playgroud)

linux hosting nginx asp.net-core nginx-reverse-proxy

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

Nginx:删除单个查询字符串参数

我有一个服务器,它返回一个包含 API 密钥的 301 HTTP 重定向 URL。重定向命中 Nginx,在那里我需要添加一个Authorization包含 API 密钥值的HTTP 标头。然后我想从发送的查询参数中删除 API 密钥

我需要翻译/google/?search=abcde&apikey=1234&version=1/google/?search=abcde&version=1

代码

location /google/ {
    proxy_set_header    X-Real-IP           $remote_addr;
    proxy_set_header    Host                $http_host;
    proxy_set_header    Authorization       "Bearer $arg_apikey";
    proxy_pass          https://google.com/;
}
Run Code Online (Sandbox Code Playgroud)

我尝试了以下操作,但不起作用: 删除 nginx 重写中的参数

location /google/ {
    if ($query_string ~ "^(.*)apikey=(.*)$") {
       rewrite ^(.*)$ $uri? permanent;
    }
    proxy_set_header    X-Real-IP           $remote_addr;
    proxy_set_header    Host                $http_host;
    proxy_set_header    Authorization       "Bearer $arg_apikey";
    proxy_pass          https://google.com/;
}
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激!

nginx nginx-reverse-proxy

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