Reputation: 307
I'm having an issue with my Nginx config file. When I load phpMyAdmin, everything works fine - except the images will not load.
Checking the error log, I see that all requests to images / other static content have "/index.php" added to the end of the request.
I would appreciate if someone could let me know what I am doing wrong.
Error Log:
2014/07/03 20:17:32 [error] 75683#0: *61 "/local/www/phpMyAdmin/themes/original/img/ajax_clock_small.gif/index.php" is not found
2014/07/03 20:17:33 [error] 75683#0: *59 "/local/www/phpMyAdmin/themes/original/jquery/jquery-ui-1.9.2.custom.css/index.php" is not found
2014/07/03 20:17:33 [error] 75683#0: *61 "/local/www/phpMyAdmin/themes/original/img/logo_left.png/index.php" is not found
2014/07/03 20:17:33 [error] 75683#0: *58 "/local/www/phpMyAdmin/themes/original/img/ajax_clock_small.gif/index.php" is not found
Nginx Config:
server {
listen XX.XX.XX.XXX:443;
ssl on;
ssl_certificate /etc/ssl/cert/example.com/example.com.crt;
ssl_certificate_key /etc/ssl/cert/example.com/example.com.key;
server_name example.com;
access_log off;
error_log /var/log/nginx/example_error.log;
root /opt/www/example.com/httpdocs;
index index.php index.html;
charset UTF-8;
try_files $uri $uri/ @backend;
location /phpmyadm/ {
alias /local/www/phpMyAdmin/;
}
location ~* ^/phpmyadm/(.+\.(jpg|jpeg|gif|png|bmp|ico|pdf|flv|swf|html|htm|txt|css|js))$ {
alias /local/www/phpMyAdmin/;
expires 365d;
etag on;
}
# Pass off php requests to Apache
location ~* \.php {
include /etc/nginx/proxypass.conf;
proxy_pass http://127.0.0.1:80;
}
location @backend {
include /etc/nginx/proxypass.conf;
proxy_pass http://127.0.0.1:80;
}
}
Upvotes: 4
Views: 2095
Reputation: 4279
Using alias
instead of root
and avoiding try_files
worked great for me:
location ^~ /secure_phpmyadmin {
alias /usr/share/phpmyadmin;
index index.php index.html index.htm;
if (!-e $request_filename) { rewrite ^ /secure_phpmyadmin/index.php last; }
location ~ \.php$ {
if (!-f $request_filename) { return 404; }
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
}
Avoid try_files
with alias
due to this issue. See this caution on the use of if
.
Upvotes: 0
Reputation: 700
Create locatation like /phpmyadmin_secure for php and for assets like in this example
#### PHPMYADMIN
location /phpmyadmin_secure {
index index.php;
location ~ ^/phpmyadmin_secure/(.+\.php)$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ~ \.(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/phpmyadmin;
}
}
####
Upvotes: 1