Nginx默认处理程序

huangapple go评论53阅读模式
英文:

Nginx default handler

问题

我在配置nginx配置方面遇到了问题。这是我的当前配置:

server {
        listen        80;
        server_name   dev.local sat.local;
        location / {
            proxy_pass http://sat:80;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
}

现在我想要将除了dev.localsat.local之外的所有请求都转发到https://prod:80,如下所示:

server {
        listen        80;
        server_name   *;
        location / {
            proxy_pass http://prod:80;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
}

我们可以做到吗?以及如何实现这个目标?请帮忙。

英文:

I'm having trouble with configuring the nginx config. Here's my current conf:

server {
        listen        80;
        server_name   dev.local sat.local;
        location / {
            proxy_pass http://sat:80;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
}

Now I want all requests to my host other than dev.local and sat.local will be passed to https://prod:80 like this

server {
        listen        80;
        server_name   *;
        location / {
            proxy_pass http://prod:80;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
}

Can we do it? And how can we do it? Please help.

答案1

得分: 0

已解决,感谢Richard Smith的答案。

server {
    listen       80  default_server;
    server_name  _;
}
英文:

Solved, thanks to Richard Smith's answer.

server {
    listen       80  default_server;
    server_name  _;
}

huangapple
  • 本文由 发表于 2023年7月20日 12:56:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76726779.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定