我的域名来自domains.google.com. 假设它是mydomainname.com
我将 DNS 设置为我想要的 IP 地址。在我的路由器上,我将端口转发80到我的计算机80和443我的计算机的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) 目前,我可以访问: 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) 我已经将ABP框架部署在Kubernetes集群中。
存在以下部署:
因此,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 …
我目前正在使用URL路径的JS项目上工作。现在,如果我使用example.com/进入我的网站,则JavaScript将无法工作,因为我实际上需要example.com/index.html。
我已经在使用反向代理来代理传递给两个不同的Docker容器。所以我的想法是将请求传递给example.com/index.html时example.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) 我有和的NodeJS Nginx的运行我是API“API_KEY”在增派头及其在没有收到req.headers并req.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
我通过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容器刷新其名称解析?
我需要根据 http 请求来源路由流量。我有两个环境,我们需要使用“$http_referer”将“/us-en”的每个http请求重定向到Environment1,其他人重定向到Environment2。
location ~ /us-en {
proxy_pass Environment1;
proxy_set_header Host Environment1;
}
Run Code Online (Sandbox Code Playgroud)
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,因为存在上游配置。
我正在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) 我正在尝试在 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) 我有一个服务器,它返回一个包含 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 ×9
nginx-config ×3
docker ×2
abp ×1
asp.net-core ×1
docker-swarm ×1
hosting ×1
http-headers ×1
kubernetes ×1
lets-encrypt ×1
linux ×1
node.js ×1
openiddict ×1
ssl ×1