我在透過 nginx 新增子網域時遇到問題 - 特別是當以字母「a」開頭的子網域新增到我們的系統時,所有子網域都會崩潰/被封鎖。這是託管在 AWS EC2 上的伺服器。
我們與 AWS 技術人員進行了大量的技術支持,以排除其他問題,我們最初使用 LetsEncrypt 進行 SSL,並發現 LetsEncrypt 對子網域有限制。 。此後,我們已經能夠為我們的伺服器添加大約 6 個其他子網域。我們已與技術人員確認,我們的設置在其他方面看起來一切正常。無法添加以字母“a”開頭的子域讓他們和我們都感到困惑。
所有子網域在「/var/etc/nginx/sites-available」中具有相同的配置設定(除了子網域):
upstream abc_app {
server unix:///var/run/puma/abc_app.sock;
}
server {
listen 80;
server_name abc.domain.com.au www.abc.domain.com.au;
return 301 https://abc.domain.com.au ;
}
server {
listen 443 ssl;
server_name www.abc.domain.com.au;
return 301 https://abc.domain.com.au ;
}
server {
listen 443 ssl;
server_name abc.domain.com.au;
ssl on;
ssl_certificate /etc/letsencrypt/live/setls.com.au/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/setls.com.au/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_connect_timeout 6000;
proxy_send_timeout 6000;
proxy_read_timeout 6000;
proxy_pass http://abc_app;
}
location ~ "^/assets/" {
root /var/app/abc.domain.com.au/current/public;
gzip_static on;
expires max;
add_header Cache-Control public;
}
}
server {
listen 80;
server_name abc.domain.com www.abc.domain.com;
return 301 https://abc.domain.com ;
}
server {
listen 443 ssl;
server_name www.abc.domain.com;
return 301 https://abc.domain.com ;
}
server {
listen 443 ssl;
server_name abc.domain.com;
ssl on;
ssl_certificate /etc/letsencrypt/live/domain.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/domain.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_connect_timeout 6000;
proxy_send_timeout 6000;
proxy_read_timeout 6000;
proxy_pass http://arc_app;
}
location ~ "^/assets/" {
root /var/app/abc.domain.com.au/current/public;
gzip_static on;
expires max;
add_header Cache-Control public;
}
}
另外,nginx 配置是:
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 1024;
#worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
client_max_body_size 8m;
# changed from 128 to 256 on 2018-12-22 by MM
server_names_hash_bucket_size 256;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# this is now taken care of in /etc/letsencrypt/options-ssl-nginx.conf
#ssl_protocols TLSv1.1 TLSv1.2;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-available/*;
}