我正在尝试设置一个具有一个域和一个子域(example.com
和download.example.com
)的 nginx Web 服务器。
server {
listen 80;
listen [::]:80;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name example.com;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
if ($scheme != "https") {
return 301 https://$host$request_uri;
} # managed by Certbot
}
server {
listen 80;
listen [::]:80;
root /var/www/download;
index index.html index.htm index.nginx-debian.html;
server_name download.example.com;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
#listen 443 ssl; # managed by Certbot
#ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
#ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
#include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
#if ($scheme != "https") {
# return 301 https://$host$request_uri;
#} # managed by Certbot
}
我可以访问example.com
,但我无法访问subdomain.example.com
。
日志:
Sep 16 19:53:32 vps456536 systemd[1]: Starting A high performance web server and a reverse proxy server... Sep 16 19:53:32 vps456536 systemd[1]: nginx.service: Failed to read PID from file /run/nginx.pid: Invalid argument Sep 16 19:53:32 vps456536 systemd[1]: Started A high performance web server and a reverse proxy server.
DNS:
$TTL 3600 @ IN SOA dns200.anycast.me. tech.ovh.net. (2017091608 86400 3600 3600000 300) IN NS dns200.anycast.me. IN NS ns200.anycast.me. IN MX 1 mx1.mail.ovh.net. IN MX 100 mx3.mail.ovh.net. IN MX 5 mx2.mail.ovh.net. IN A SOME_IP IN AAAA SOME_IP IN TXT "1|example.com" 600 IN TXT "v=spf1 include:mx.ovh.com ~all" _autodiscover._tcp IN SRV 0 0 443 mailconfig.ovh.net. _imaps._tcp IN SRV 0 0 993 ssl0.ovh.net. _submission._tcp IN SRV 0 0 465 ssl0.ovh.net. autoconfig IN CNAME mailconfig.ovh.net. autodiscover IN CNAME mailconfig.ovh.net. ftp IN CNAME example.com. imap IN CNAME ssl0.ovh.net. mail IN CNAME ssl0.ovh.net. pop3 IN CNAME ssl0.ovh.net. smtp IN CNAME ssl0.ovh.net. www IN MX 1 mx1.mail.ovh.net. www IN MX 100 mx3.mail.ovh.net. www IN MX 5 mx2.mail.ovh.net. www IN A SOME_IP www IN AAAA SOME_IP www IN TXT "l|pl" www IN TXT "3|welcome"
答案1
向您的 DNS 区域添加 A 记录或 CNAME download.example.com
。当然,仅在 nginx 中定义 vhost 不足以让客户端找到它。