首先请原谅我这个问题是否简单。
我有一台装有 Ubuntu 和 nginx 的服务器。http
使用时始终可以正常工作,但在添加证书并尝试启用后,https
我收到了此错误nginx: [emerg] host not found in upstream "api"
。
这是我的配置:
upstream api {
least_conn;
server 176.9.91.243:7123;
}
upstream api2 {
least_conn;
server 176.9.32.170:7123;
}
server {
# listen 80;
listen 443;
ssl on;
ssl_certificate /etc/ssl/chain.crt;
ssl_certificate_key /etc/ssl/ssl_key.key;
add_header Strict-Transport-Security "max-age=31536000";
add_header Content-Security-Policy "block-all-mixed-content";
root /var/www/hosting;
index index.html index.htm;
client_max_body_size 15m;
server_name serverName.com;
gzip on;
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain application/javascript application/x-javascript text/javascript text/xml text/css;
set $const 1;
location /signalr {
limit_conn addr 1000;
access_log off;
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 https://api2/signalr;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 120s;
proxy_buffering off;
keepalive_timeout 120s;
}
location /api/signalr {
limit_conn addr 1000;
access_log off;
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 https://api2/signalr;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 120s;
proxy_buffering off;
keepalive_timeout 120s;
}
location /api/notifications{
limit_conn addr 1000;
access_log off;
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 https://api2/notifications;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 120s;
proxy_buffering off;
keepalive_timeout 120s;
}
location /api/notificationhistory{
limit_conn addr 1000;
access_log off;
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 https://api2/notificationhistory;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 120s;
proxy_buffering off;
keepalive_timeout 120s;
}
location /api/swagger {
access_log off;
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 https://api/swagger;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 120s;
proxy_buffering off;
keepalive_timeout 120s;
}
location /api {
limit_conn addr 3000;
rewrite /api(.*) /$1 break;
proxy_read_timeout 60s;
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 https://api;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_redirect off;
#access_log /var/log/nginx/api-access.log upstreamlog;
}
}
问题只发生在api
上游,而上游api2
工作正常。如果我直接使用 IP,proxy_pass
它也能正常工作。我错过了什么?谢谢。
答案1
我很确定你错过了这个resolver
指令:http://nginx.org/en/docs/http/ngx_http_core_module.html#resolver