代码之家  ›  专栏  ›  技术社区  ›  Olivier Pons

nginx:“/”url不尝试索引.html文件

  •  2
  • Olivier Pons  · 技术社区  · 7 年前

    my.domainname.com/unity/index.html “手动操作,就行了 当我尝试的时候” my.domainname.com/unity/

    (最重要的是最新的行,当用户想要访问 /unity 路径)

    server {
      listen *:443 ssl;
      server_name "~^my\.domainname\..*$";
    
      index index.html index.htm;
    
      access_log /var/log/nginx/proxy-access.log proxylog;
      error_log /var/log/nginx/proxy-error.log error;
    
      ssl_certificate /var/lib/acme/live/my.domainname.com/fullchain;
      ssl_certificate_key /var/lib/acme/live/my.domainname.com/privkey;
      ssl_trusted_certificate /var/lib/acme/live/hive.battlesoop.fr/chain;
      ssl_stapling on;
      ssl_stapling_verify on;
    
      location '/.well-known/acme-challenge' {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Server $host;
        proxy_pass http://acmetool;
      }
    
      # Add CORS access to all = '*'
      add_header 'Access-Control-Allow-Origin' '*' always;
      add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
      add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept' always;
      add_header 'Access-Control-Allow-Credentials' 'true' always;
    
      # unity
      location ~* ^/unity(?<p>.*) {
        root /web/htdocs/my.domainname.com/unity;
        index index.html index.htm;
        try_files /$p =403;
        access_log off;
        expires 1h;
      }
    }
    
    1 回复  |  直到 7 年前
        1
  •  2
  •   Richard Smith    7 年前

    try_files index 功能由 文件 尾随词 / . 看到了吗 this document 详情。

    我不能让它与你命名的捕获一起工作,但是如果你把“/unity”这个词去掉 root 声明,可以使用常规方法。

    location ~* ^/unity {
        root /web/htdocs/my.domainname.com;
        index index.html index.htm;
        try_files $uri $uri/ =403;
        access_log off;
        expires 1h;
    }