
我遇到了一個我不明白的nginx問題。
我能夠正確設置並調用www.example.tech
和example.tech
。
但是,當另一個子網域(例如)新增survey.example.tld
至清單時,其他兩個仍然有效,但survey.example.tld
不起作用。
在 chrome 中,嘗試呼叫時收到以下錯誤訊息http://survey.example.tech/
:
無法存取此網站 檢查 Survey.example.tech 中是否有拼字錯誤。 DNS_PROBE_FINISHED_NXDOMAIN
我很確定其中沒有錯字,因為我已經檢查了三次。而且,www.example.tech
仍然example.tech
工作。
我使用 nginx 將請求轉發到 Gunicorn/Flask 應用程式。
因此我將我的配置放入/etc/nginx/sites-enabled
$ cat /etc/nginx/sites-enabled/survey.example.tech
server {
server_name example.tech www.example.tech survey.example.tech;
location /static {
alias /opt/example.tech/my-domain-Survey-Website/static;
}
location / {
proxy_pass http://localhost:8003;
include /etc/nginx/proxy_params;
proxy_redirect off;
# Max file size allowed for upload by user. Here 1M = 1 Megabyte
client_max_body_size 1M;
# prevents warning messages when setting up let's encrypt
proxy_headers_hash_max_size 512;
proxy_headers_hash_bucket_size 128;
# Enable Websocket by adding these two options
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
}
以及相應的服務/etc/systemd/system
$ cat /etc/systemd/system/gunicorn-my-domain-survey-flask.service
[Unit]
Description = gunicorn for my-domain website
After = network.target
[Service]
Environment=LOG_PATH=/opt/example.tech/example.tech-Survey-Website/gunicorn-logs
User = ubuntu
Group = ubuntu
WorkingDirectory = /opt/example.tech/example.tech-Survey-Website
ExecStart = /opt/example.tech/venv/bin/gunicorn --bind 127.0.0.1:8003 -w 1 --log-level debug --access-logfile ${LOG_PATH}/access-logfile.log --error-logfile ${LOG_PATH}/error.log --capture-output run_survey_website:app
[Install]
WantedBy = multi-user.target
當我運行這個時,除了 之外,一切正常survey.example.tech
。
這裡發生了什麼事?我是否誤解了 nginx 的子網域設定?
答案1
nginx設定沒問題。
您需要新增一條survey.example.tech
指向您伺服器 IP 位址的 DNS 記錄。