我正在使用DigitalOcean Debian 9 + PHP 7.0 + NGINX 1.10.3-1并尝试安装Joomla! CMS,但在第一个安装屏幕上(example.com/installation/index.php)我注意到图像损坏(这是Joomla徽标),它看起来像这样:
该图像的img src属性包含“/template/images/joomla.png”,但图像实际上位于“/installation/template/images/joomla.png”,这意味着我错过了“/ installation” /“part。
这是我的PHP的nginx conf部分:
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}
取消注释“/etc/php/7.0/fpm/php.ini”中的“cgi.fix_pathinfo”行,并将值更改为0.
“/snippets/fastcgi-php.conf”文件包含以下内容:
# regex to split $uri to $fastcgi_script_name and $fastcgi_path
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# Check that the PHP script exists before passing it
try_files $fastcgi_script_name =404;
# Bypass the fact that try_files resets $fastcgi_path_info
# see: http://trac.nginx.org/nginx/ticket/321
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
fastcgi_index index.php;
include fastcgi.conf;
我注意到,一旦我评论PATH_INFO部分,图像就会加载:
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
但我所有进一步尝试找出问题的根源都是不成功的,请帮我解决这个问题。
答案 0 :(得分:1)
定义位置时,nginx按照外观顺序处理它们。 匹配文件的第一个规则被执行,其他规则被忽略。 这就是你首先放置一些安全性,接下来是静态资产,以及最后放置php的方法:
server {
listen 80;
server_name example.com;
root /full/path/to/your/joomla/root/directory;
# allow letsencrypt
location ~ /.well-known/acme-challenge {
allow all;
access_log off;
log_not_found off;
}
# handle some security and logs
location = /favicon.ico {
access_log off;
log_not_found off;
}
location = /robots.txt {
allow all;
access_log off;
log_not_found off;
}
# Deny access to htaccess and other hidden files
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
# handle static xml files
location ~* \.(xml)$ {
access_log off;
log_not_found off;
add_header Pragma no-cache;
add_header Cache-Control "no-cache, no-store, must-revalidate, post-check=0, pre-check=0";
gzip off;
}
# include in each host for static content to run with cache and without logs, with CORS enabled (for fonts)
location ~* \.(jpg|jpeg|gif|png|bmp|css|js|ico|txt|pdf|swf|flv|mp4|mp3|eot|ttf|svg|woff|woff2)$ {
add_header Access-Control-Allow-Origin *;
add_header Cache-Control "public";
access_log off;
log_not_found off;
tcp_nopush on;
sendfile on;
expires 15d;
# Enable gzip
gzip on;
gzip_comp_level 6;
gzip_vary on;
gzip_types text/richtext text/plain text/css text/x-script text/x-component text/x-java-source application/javascript application/x-javascript text/javascript text/js image/x-icon application/x-perl application/x-httpd-cgi text/xml application/xml application/xml+rss application/json multipart/bag multipart/mixed application/xhtml+xml font/ttf font/otf image/svg+xml application/vnd.ms-fontobject application/ttf application/x-ttf application/otf application/x-otf application/truetype application/opentype application/x-opentype application/eot application/font application/font-sfnt;
}
# html
location ~* \.(html|htm|shtml)$ {
max_ranges 0;
etag off;
if_modified_since off;
add_header Last-Modified "";
gzip on;
gzip_buffers 64 128k;
gzip_comp_level 9;
gzip_http_version 1.1;
gzip_min_length 0;
gzip_types text/plain;
gzip_vary off;
}
# allow wordpress, joomla, etc to work properly
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
# handle php
location ~ .php$ {
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
try_files $uri $uri/ /index.php?q=$uri&$args;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REQUEST_SCHEME $scheme;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param HTTP_PROXY "";
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param HTTP_CF_IPCOUNTRY $http_cf_ipcountry;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
}
答案 1 :(得分:1)
我们的一位客户遇到了同样的问题,我们在this post中解释了如何修复它。基本上,您的try_files
行不正确。
顺便说一句,cgi.fix_pathinfo
必须设置为1,而不是零(默认为0,因此取消注释它不能解决问题。)