【发布时间】:2016-01-24 22:14:30
【问题描述】:
请尽可能明确地提供帮助。我已经在 Ubuntu 15 上运行 nginx 的家庭服务器上设置了一个域,并且我有 dns 指向它。我可以使用该域来访问该站点,如果我将 /subdirectory 附加到它,我就可以在子目录中启动页面。我想要做的是让子域直接进入正确的根目录。即:mysite.com = /index.htm, subdomain.mysite.com = ./subdirectory 文件所在的位置。 我已经尝试了每一个建议,包括那些流行的和那些受到批评的,要么我得到一个错误重新启动 Nginx,要么我得到一个“找不到服务器”错误。我试过用我的 DNS 服务器设置 cname 别名,但这也不起作用。
工作配置文件如下:
##
server {
server_name "~^(?<sub>.+)\.domain\.tld$";
index index.php index.html index.htm;
root //media/user/ednet/$sub;
ssl_certificate REMOVED FOR SECURITY
ssl_certificate_key REMOVED FOR SECURITYY
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!Anull:!md5;
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
# root //media/user/ednet;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm;
#=========================Locations=============================
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
# root /usr/share/nginx/html;
}
#============================================================PHP=========================================================
location ~ \.php$ {
try_files $uri =404;
# fastcgi_split_path_info ^(.+\.php) (/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
===================== 我已经尝试过代理、重定向以及我能想到的所有其他方法——包括阅读 Nginx 手册和 wiki 中的说明。 谢谢
【问题讨论】:
标签: nginx subdomain subdirectory multisite