请尽可能明确地提供帮助。我在Ubuntu 15上运行nginx的家庭服务器上设置了一个域,我有dns指向它。我可以使用域来访问该站点,如果我追加/子目录,我可以启动子目录中的页面。我想要做的是让子域直接转到正确的根目录。即: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中的说明。 感谢
答案 0 :(得分:0)
浏览器找不到快速“服务器”表示未设置DNS。您的子域需要使用以下任一方法解析为服务器的公共IP地址:
对DNS的更改可能需要数小时才能传播。
重新启动错误nginx
表示配置文件中存在语法错误。
您的配置文件没有明显的语法错误,但有一些奇怪的元素:
root
指令出现两次index
指令出现两次root
指令有两个前导//
,通常会有一个您已配置IPv4和IPv6,如果您有IPv6连接,则可以正常使用。
您将此服务器标记为default_server
,这意味着即使server_name
正则表达式不匹配也会使用它。因此,如果您使用从根目录返回文件的子域向服务器提供,这意味着正则表达式无法匹配,但默认情况下使用server
块。在这种情况下,请检查正则表达式。
总之,首要任务是修复DNS。除非子域解析为服务器的IP地址,否则无效。