将子域路由到nginx上的子目录
请尽可能明确地提供帮助。我已经在Ubuntu 15上运行nginx的家庭服务器上设置了一个域,我的dns指向它。我可以使用该域访问该站点,如果我将/subdirectory附加到该域,我就可以启动子目录中的页面。我试图做的是让子域直接转到正确的根。Ie:mysite.com=/index.htm,subdomain.mysite.com=./文件所在的子目录。 我尝试了每一个建议,包括那些流行的和那些被批评的,或者我在重新启动Nginx时出错,或者我遇到了一个“服务器未找到”错误。我已经尝试在DNS服务器上设置cname别名,但这也不起作用 工作配置文件如下所示:将子域路由到nginx上的子目录,nginx,subdomain,subdirectory,multisite,Nginx,Subdomain,Subdirectory,Multisite,请尽可能明确地提供帮助。我已经在Ubuntu 15上运行nginx的家庭服务器上设置了一个域,我的dns指向它。我可以使用该域访问该站点,如果我将/subdirectory附加到该域,我就可以启动子目录中的页面。我试图做的是让子域直接转到正确的根。Ie:mysite.com=/index.htm,subdomain.mysite.com=./文件所在的子目录。 我尝试了每一个建议,包括那些流行的和那些被批评的,或者我在重新启动Nginx时出错,或者我遇到了一个“服务器未找到”错误。我已经尝试在D
##
服务器{
服务器名称“~^(?.+)\.domain\.tld$”;
index.php index.html index.htm;
root//media/user/ednet/$sub;
为安全起见,已删除ssl\U证书
为安全起见,已删除ssl\u证书\u密钥
ssl_协议TLSv1 TLSv1.1 TLSv1.2;
ssl_密码高:!Anull:!md5;
监听80个默认_服务器;
侦听[:]:80默认_服务器;
#SSL配置
#
侦听443 ssl默认_服务器;
侦听[:]:443 ssl默认_服务器;
#root//media/user/ednet;
#如果您正在使用php,请将index.php添加到列表中
index.php index.html index.htm;
#========================================位置=============================
地点/{
#首先尝试将请求作为文件提供,然后
#作为目录,然后返回显示404。
try_files$uri$uri/=404;
}
错误\u第404/404.html页;
错误\u第500页502 503 504/50x.html;
location=/50x.html{
#root/usr/share/nginx/html;
}
#=====================================================================================PHP=========================================================
位置~\.php${
try_files$uri=404;
#fastcgi\u split\u path\u info^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index.php;
fastcgi\参数脚本\文件名$document\根$fastcgi\脚本\名称;
包括fastcgi_参数;
}
}
====================
我尝试过代理、重定向和我能想到的一切——包括阅读Nginx手册和wiki中的说明。
谢谢浏览器快速显示的“未找到服务器”提示未设置DNS。您的子域需要使用以下任一方式解析为服务器的公共IP地址:
- 指向特定于主域的A记录的特定CNAME记录
- 指向服务器的IP地址(全部捕获)记录
- 指向服务器的IP地址
指令出现两次root
指令出现两次index
指令有两个前导的root
,其中一个通常会起作用/
default\u服务器
,这意味着即使server\u名称
regex不匹配,也将使用它。因此,如果向服务器提供从根目录返回文件的子域,这意味着正则表达式无法匹配,但默认情况下使用了server
块。在这种情况下,请检查正则表达式
总之,首要任务是修复DNS。除非子域解析为服务器的IP地址,否则任何操作都将无效
##
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;
}
}