我正在尝试在我的数字海洋实例上设置一个子域,并且据我所知,我的域的区域文件和我的站点的 Nginx 配置中的所有内容都是正确的 - 我在这里做错了什么吗?
主域名功能正常 - 它什么都没显示,因为我还没有配置站点文件。子域名总是转发到我在同一 DO 实例上托管的另一个域名。
DNS 区域:
$ORIGIN smsteammenus.com.
$TTL 1800
smsteammenus.com. IN SOA ns1.digitalocean.com. hostmaster.smsteammenus.com. 1452088962 10800 3600 604800 1800
smsteammenus.com. 1800 IN NS ns1.digitalocean.com.
smsteammenus.com. 1800 IN NS ns2.digitalocean.com.
smsteammenus.com. 1800 IN NS ns3.digitalocean.com.
smsteammenus.com. 1800 IN A **IP address**
www.smsteammenus.com. 1800 IN CNAME smsteammenus.com.
*.smsteammenus.com. 1800 IN CNAME smsteammenus.com.
staging.smsteammenus.com. 1800 IN A **the same IP address as above**
*.staging.smsteammenus.com. 1800 IN CNAME staging.smsteammenus.com.
子域名 Nginx 配置:
server{
listen 80;
listen [::]:80;
root /var/www/smsteammenus.com/staging;
index index.php index.html index.htm;
server_name staging.smsteammenus.com;
location / {
# try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
主域名 Nginx 配置:
server {
listen 80;
listen [::]:80;
root /var/www/smsteammenus.com/html;
index index.php index.html index.htm;
server_name smsteammenus.com www.smsteammenus.com;
location / {
# try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
我将其与 ServerFault 上的类似问题进行了比较但无济于事,并已三次检查我是否已完成所有正确的步骤(链接到已启用站点、重新启动 nginx 等),但无法使其正常工作。
答案1
在此期间,我一直在尝试这个。
首先,我为子域创建了一个完全独立的目录,而不是尝试在同一个目录中运行两个域。然后,我将第二个 Nginx 配置文件的内容复制到主域的 Nginx 配置中,修改了域需要查看的目录,一切正常。