我们有NGinX作为PHP Web应用程序的代理服务器。 PHP脚本由PHP-FPM进程提供。 以下是nginx的configuration:
location /app/ { alias /var/www/html; location ~* \.(js|css|png|jpg|jpeg|gif|ico|eot|svg|ttf|woff)$ { alias /var/www/html; expires 24h; log_not_found on; try_files $uri $uri; } rewrite /app.* /app/index.php?$args; location ~ \.php$ { try_files $uri =404; # typical php-fpm configuration } } # wordpress site hosted on root of the domain location / { try_files $uri $uri/ /index.php?$args; } location ~* \.(js|css|png|jpg|jpeg|gif|ico|eot|svg|ttf|woff)$ { expires 24h; log_not_found off; auth_basic off; }
PHP应用程序本身是基于Yii的。 现在的问题是,当NGINX服务一个静态图像时,它是随机截断实际path(有时在80个字符后,或者有时在URL后面4个短划线之后)。 例如
可以说,访问的URL是example.com/app/themes/app/images/some_folder/some_image_name.png ,它显示404,并在error.log我看到NGinx正试图find以下path/var/www/html/app/themes/app/images/some_folder/**some_image_name.pn/**从url中删除),而另一个文件名称短于罪魁祸首的图片则位于同一位置。
编辑:我们已经注意到了一种模式,实际上nginx是在原来的$ uri之后再添加$ uri,也就是在上面提到的例子中,它是用$ / uri的起始字符'/'replace'g', '/'使用'.png'。 希望它有助于debugging。 🙂
将alias更改为root目录path将解决您的问题。
location ~* \.(js|css|png|jpg|jpeg|gif|ico|eot|svg|ttf|woff)$ { root /var/www/html; expires 24h; log_not_found on; try_files $uri $uri; }