Nginx无法打开子目录的静态文件

时间:2018-10-24 06:43:28

标签: laravel nginx nginx-config

我尝试从子目录( / var / www / data / www / hotels / public / sitemaps / by / sitemap-hotels)打开站点地图( https://example.com/hotels/sitemaps/by/sitemap-hotels.xml )。 xml ),但我得到一个空白页面。目录 hotels 是一个laravel子项目,我将其包含在主项目中。

  1. 主要项目:/var/www/data/www/example.com
  2. laravel子项目:/ var / www / data / www / hotels

Conf:

{
    server_name example.com;
    charset UTF-8;
    disable_symlinks if_not_owner from=$root_path;
    index index.php;
    root $root_path;
    set $root_path /var/www/data/www/example.com/public;
    access_log off ;
    error_log /var/www/httpd-logs/example.com.error.log notice;
    include /etc/nginx/vhosts-includes/*.conf;
    location / {
        if ($http_host !~ "^example.com"){ 
            return 301 $scheme://example.com$request_uri;
        } 

        try_files $uri $uri/ /index.php?_url=$uri&$args;

        location ~ [^/]\.ph(p\d*|tml)$ {
            try_files /does_not_exists @php;
        }
    }

    location @php {
        fastcgi_index index.php;
        fastcgi_param PHP_ADMIN_VALUE "sendmail_path = /usr/sbin/sendmail -t -i -f webmaster@example.com";
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_split_path_info ^((?U).+\.ph(?:p\d*|tml))(/?.+)$;
        try_files $uri =404;
        include fastcgi_params;
    }

    location @fallback {
    }

    location ^~ /hotels/sitemaps/ {
        alias  /var/www/data/www/hotels/public/sitemaps/;
        try_files $uri $uri =404;

        location ~* \.(xml)$ {
            expires 7d; 
        }
    }

    location ^~ /hotels {
        alias /var/www/data/www/hotels/public;
        try_files $uri $uri/ @hotels;

        location ~* \.php {
            fastcgi_pass unix:/run/php/php7.1-fpm.sock;
            fastcgi_split_path_info ^((?U).+\.ph(?:p\d*|tml))(/?.+)$;
            include fastcgi_params;
        }
    }

    location @hotels {
        rewrite ^/hotels/(.*)$ /hotels/index.php/$1 last;
    }

    location ~* ^.+\.(rss|atom|jpg|jpeg|gif|png|ico|rtf|js|css)$ {
        expires 7d;
        etag on;
    }
}

0 个答案:

没有答案