Debian 9 + PHP7.0-FPM + NGINX 1.10.3-1 path_info issue

天涯浪子 提交于 2021-01-28 10:12:11

问题


I'm using DigitalOcean Debian 9 + PHP 7.0 + NGINX 1.10.3-1 and trying to install Joomla! CMS, but at the very first installation screen (example.com/installation/index.php) I've noticed a broken image (which is the Joomla logo), and it looks like this:

img src attribute for that image contains "/template/images/joomla.png", but the image is actually located at "/installation/template/images/joomla.png" which means I'm missing the "/installation/" part.

Here is my nginx conf part for the PHP:

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}

The "cgi.fix_pathinfo" line at "/etc/php/7.0/fpm/php.ini" is uncommented and the value changed to 0.

And the "/snippets/fastcgi-php.conf" file contains the following:

# 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;

I've noticed that the image is loading once I comment the PATH_INFO part:

set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;

But all my further attempts to figure out the root of the problem are unsuccessful, please help me to fix this.


回答1:


One of our clients had the same problem, and we explained how to fix it in this post. Essentially, your try_files line is incorrect.

By the way, the cgi.fix_pathinfo must be set to 1, and not to zero (it defaults to 0, so uncommenting it does not solve the problem.)




回答2:


When you define locations, nginx processes them in order of appearance. The first rules that matches a file get's executed and the others ignored. This is how you put some security first, static assets next, and php in the end:

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; 
}

}


来源:https://stackoverflow.com/questions/44991666/debian-9-php7-0-fpm-nginx-1-10-3-1-path-info-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!