Nginx php-fpm 子目录

标签 nginx php

我想通过 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/pmaroot/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/

相关文章:

php - ajax调用login.php,响应失败

PHP 在具有多个表单输入的同一列中添加数据

php - 防止选择零值。忽略零值(总计)

php - 如何在 PHP 数据库中存储 2.00 格式的值?

reactjs - 使用 Nginx 在单个域上运行多个 React 应用程序

php - 在 Nginx 上模拟 Apache 目录别名

ssl - 如何配置 Nginx 网络服务器以使用 AWS RDS SSL,同时在 Nginx 网络服务器和访问者浏览器之间维护 https

Nginx 代理或根据用户代理重写,不带 if

php - 来自 phpMyAdmin 的 Json 数据不会在网站上更新

deployment - Play 框架 2.0 中的路由不适用于 Nginx 下的独立应用程序