我正在尝试向我的 nginx 服务器添加子域名,但似乎无法正常工作。这是我的主服务器的配置文件:
server {
listen 80;
server_name www.kevin-whitaker.net;
rewrite ^/(.*) http://kevin-whitaker.net permanent;
}
server {
listen 80;
server_name kevin-whitaker.net;
access_log /home/admin/public_html/kevin-whitaker.net/log/access.log;
error_log /home/admin/public_html/kevin-whitaker.net/log/error.log;
root /home/admin/public_html/kevin-whitaker.net/public/;
index index.html;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect false;
if (-f $request_filename/index.html) {
rewrite (.*) $1/index.html break;
}
if (-f $request_filename.html) {
rewrite (.*) $1.html break;
}
}
}
对于子域名:
server {
listen 80;
server_name www.pci.kevin-whitaker.net;
rewrite ^/(.*) http://pci.kevin-whitaker.net permanent;
}
server {
listen 80;
server_name pci.kevin-whitaker.net;
access_log /home/admin/public_html/pci.kevin-whitaker.net/log/access.log;
error_log /home/admin/public_html/pci.kevin-whitaker.net/log/error.log;
root /home/admin/public_html/pci.kevin-whitaker.net/public/;
index index.html;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect false;
if (-f $request_filename/index.html) {
rewrite (.*) $1/index.html break;
}
if (-f $request_filename.html) {
rewrite (.*) $1.html break;
}
}
}
主域名 (kevin-whitaker.net) 功能正常。但是,当我尝试浏览或 ping 子域名时,子域名无法解析。我是否遗漏了其他步骤?
答案1
如果上面使用的域名就是您所说的域名,那么您的子域名可能无法正常工作,因为没有它们的 DNS 条目。请仔细查找并查找回复中的答案部分。
dig kevin-whitaker.net
有正确的答案部分,而dig pci.kevin-whitaker.net
缺少答案部分。只需输入 DNS 条目,您就可以开始了。