【问题标题】:PhpMyAdmin wrong display in Nginx using reverse proxy使用反向代理在 Nginx 中的 PhpMyAdmin 错误显示
【发布时间】:2020-10-23 13:19:59
【问题描述】:
  • 我在 Nginx 中运行一个 NodeJS 应用程序,反向代理到端口 3000
  • PhpMyAdmin 已配置,显然在 /phpmyadmin 中运行
  • /etc/nginx/sites-available/default 配置如下:
server {
    listen 80;
    listen [::]:80;

    root /var/www/html;
    index index.php index.html index.htm index.nginx-debian.html;

    server_name localhost mywebsite.com www.mywebsite.com;

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

    location /phpmyadmin {
        root /var/www/html/phpmyadmin/;
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; 
    }
}

我设法使所有工作都按我的意愿进行,但 PhpMyAdmin 的显示效果不佳:

在该文件中设置反向代理之前,PhpMyAdmin 运行良好。我假设我在default 文件中遗漏了一些东西。
有什么想法吗?谢谢


致 Ivan Shatsky 的回复: @IvanShatsky

我尝试用您的代码替换,但它下载了一个文件(它不读取 .php 文件) - 所以,我又添加了几行:

location ^~ /phpmyadmin {
    index index.php;
    try_files $uri $uri/ /phpmyadmin/index.php$is_args$args;
    
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

结果和之前一样。
当我检查网络资源时,会发生以下情况:

我已经执行了chmod 777 -R /var/www/html/phpmyadmin,但没有任何变化。我需要有https吗? - 我目前正在尝试 http。

【问题讨论】:

    标签: nginx phpmyadmin reverse-proxy


    【解决方案1】:

    我想知道它是如何运行的。假设您的 phpMyAdmin 位于 /var/www/html/phpmyadmin 目录中,试试这个:

    location /phpmyadmin {
        index index.php;
        try_files $uri $uri/ /phpmyadmin/index.php$is_args$args;
    }
    

    【讨论】:

    • 嗨@Ivan 我已根据您的回复在问题中添加了更新,谢谢。
    • @J.Diaz 我的错误,^~ 不需要,尝试按原样更新location 块,不需要在其中添加 fastcgi 配置。但是,由于您收到 403 Forbidden,恐怕您的问题的原因是对 phpMyAdmin 资产文件的权限不正确。另一个可能的原因是 SELinux 标签不正确,您的服务器上是否启用了 SELinux?
    猜你喜欢
    • 2018-06-23
    • 2014-08-26
    • 2021-07-01
    • 2015-09-11
    • 2020-03-12
    • 2016-05-22
    • 2017-11-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多