我想通过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错误。
答案 0 :(得分:1)
当您设置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;
}
答案 1 :(得分:1)
这是我在nginx中使用的代码。
location /phpMyAdmin {
root /var/www/default;
index index.php index.html;
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/default$fastcgi_script_name;
include fastcgi_params;
}
}