我正在使用nginx设置代理。想要将一堆server_name添加到相同配置的映像:
server {
listen 1.2.3.4:443 ssl;
server_name 1.abc.org;
access_log off;
error_log off;
ssl_certificate /etc/nginx/ssl/test.crt;
ssl_certificate_key /etc/nginx/ssl/test.key;
keepalive_timeout 60;
location / {
proxy_pass https://1.abc.org;
include /etc/nginx/conf.d/proxy.conf;
proxy_set_header X-Forwarded-Proto https;
}
}
我想添加一堆server_name:
应该是
server {
listen 1.2.3.4:443 ssl;
server_name $server_name;
access_log off;
error_log off;
ssl_certificate /etc/nginx/ssl/test.crt;
ssl_certificate_key /etc/nginx/ssl/test.key;
keepalive_timeout 60;
location / {
proxy_pass https://$server_name;
include /etc/nginx/conf.d/proxy.conf;
proxy_set_header X-Forwarded-Proto https;
}
}
和 server_name = 1.abc.org,2.abc.org,3.abc.org,4.abc.org,aish.abc.org ......
然后我可以通过像上面一行添加server_name来做更容易的工作,不需要复制配置块。我该怎么办?
感谢。
答案 0 :(得分:0)
查看使用上游块
upstream backend {
server backend1.example.com weight=5;
server backend2.example.com:8080;
server unix:/tmp/backend3;
}
server {
location / {
proxy_pass http://backend;
}
}