我想通过 nginx 运行 php-fpm,但对于不同的位置我想指定不同的根:
对于路径:
http://localhost/->/usr/share/nginx/html
http://localhost/pma ->/var/www/default/phpMyAdmin/
http://localhost/pga ->/var/www/default/phpPgAdmin/
我的配置无法正常工作:
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
try_files $uri =404;
index index.php index.html;
location / {
}
# redirect server error pages to the static page /40x.html
#
error_page 404 /404.html;
location = /40x.html {
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
location /pma {
root /var/www/default/phpMyAdmin;
try_files $uri =404;
index index.html index.php;
}
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
我总是收到 404 错误。
最佳答案
当您设置location/pma
和root/var/www/default/phpMyAdmin
请求http://server/pma/index.php
是搜索文件 /var/www/default/phpMyAdmin/pma/index.php
。
使用这样的东西:
location /pma/ {
rewrite /pma/ /phpMyAdmin/ last;
}
location /phpMyAdmin {
root /var/www/default/
try_files $uri =404;
index index.html index.php;
}
或将/var/www/default/phpMyAdmin 重命名为/var/www/default/pma 并将配置更改为
location /pma {
root /var/www/default/
try_files $uri =404;
index index.html index.php;
}
关于Nginx php-fpm 子目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24328628/