无法添加/加载Nginx子域(子域重复)

无法添加/加载Nginx子域(子域重复),nginx,subdomain,Nginx,Subdomain,长话短说,我在代码中添加了一个子目录(/main site/sub),我想将它添加到我的nginx配置中。但是,我无法阻止子域错误地加载(some.web.site/sub/sub/index.html)而不是加载(some.web.site/sub/index.html) 以下是配置文件: server { listen 80; server_name site.com www.site.com ~^((?<subdomains>.+)?\.)?site.com$;

长话短说,我在代码中添加了一个子目录(/main site/sub),我想将它添加到我的nginx配置中。但是,我无法阻止子域错误地加载(some.web.site/sub/sub/index.html)而不是加载(some.web.site/sub/index.html)

以下是配置文件:

server {
  listen 80;
  server_name site.com www.site.com ~^((?<subdomains>.+)?\.)?site.com$;

  root /srv/site;
  index index.html index.htm;

  access_log /var/log/nginx/site/access.log;
  error_log  /var/log/nginx/site/error.log;

  if ($subdomains !~* "^(www)?$") {
    rewrite ^/(.*)$ https://$subdomains.site.com/$1 redirect;
  }

  rewrite ^/(?!index)(.*).html$    $1        permanent;
  rewrite ^/stuff1$      /st1 redirect;
  rewrite ^/stuff2$      /st2 redirect;
  rewrite ^/stuff3$      /st3 redirect;
  rewrite ^/stuff4$      /st4 redirect;
  rewrite ^/stuff5$      /st5 redirect;

  location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to 404
    # hide html extension
    try_files $uri.html $uri/ =404;
  }
## Where this stays in or not the result is the same
## site.com/sub/sub/index and not site.com/sub/index
## location /sub/ {
##   root /srv/site;
## }

  # Redirect 404 to index
  error_page 404 = @fallback;
  location @fallback {
    rewrite  .*  / permanent;
  }
}
服务器{
听80;
服务器名称site.com www.site.com~ ^((?。+)?\)?site.com$;
root/srv/site;
index.html index.htm;
access_log/var/log/nginx/site/access.log;
error\u log/var/log/nginx/site/error.log;
如果($subdomains!~*“^(www)?$”){
重写^/(.*)$https://$subdomains.site.com/$1重定向;
}
重写^/(?!index)(.*).html$$1永久;
重写^/stuff1$/st1重定向;
重写^/stuff2$/st2重定向;
重写^/stuff3$/st3重定向;
重写^/stuff4$/st4重定向;
重写^/stuff5$/st5重定向;
地点/{
#首先尝试将请求作为文件提供,然后
#作为目录,然后返回到404
#隐藏html扩展名
try_files$uri.html$uri/=404;
}
##不管它在哪里,结果都是一样的
##site.com/sub/sub/index而不是site.com/sub/index
##地点/分处/{
##root/srv/site;
## }
#将404重定向到索引
错误\u第404页=@回退;
位置@fallback{
重写。*/永久;
}
}
谢谢大家!

以下是解决方案:

rewrite ^/(?!index)(.*).html$    /$1        permanent;
我必须在1美元之前加上a/号