在 Nginx 上使用 PHP 页面在 404 上运行

在 Nginx 上使用 PHP 页面在 404 上运行

PHPMyadmin我对服务器还不太熟悉,正在使用 Nginx (以及 SSL 和 Wordpress)设置我的第一个 Web 服务器。我正在使用的操作系统是一个Debian 10 Docker图像。

我正在跟进关于如何拥有LEMP堆栈的教程。最后,我PHP通过创建一个 php.info 页面并在之后运行它(启动 nginx 和 php 服务)来检查它是否确实有效。但是我继续运行到 404 页面。当我phpinfo()在图像的命令行上键入时,我正确地获得了所有信息。这是我的代码。

example.com位于/etc/nginx/站点可用/

server {
    listen 443 ssl;
    listen [::]:443 ssl;

    include snippets/self-signed.conf;
    include snippets/ssl-params.conf;

    root /var/www/example.com;
    index index.php index.html index.htm;

    server_name example.com www.example;

    location / {
        try_files $uri $uri/ =404;
        autoindex on;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
    }
}

server {
    listen 80;
    listen [::]:80;

    server_name example.com www.example.com;

    return 301 https://$server_name$request_uri;
}

server {
   listen 80;
   server_name pma.com www.pma.com;
   root /usr/share/phpMyAdmin;

   location / {
      index index.php;
   }

   location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
      access_log off;
      expires 30d;
   }

   location ~ /\.ht {
      deny all;
   }

   location ~ /(libraries|setup/frames|setup/libs) {
      deny all;
      return 404;
   }

   location ~ \.php$ {
      include /etc/nginx/fastcgi_params;
      fastcgi_pass 127.0.0.1:9000;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME /usr/share/phpMyAdmin$fastcgi_script_name;
   }
}

info.php位于/var/www/example.com/

<?php
phpinfo();
?>

我在构建时使用 shell 脚本文件将所有内容安装到我的 docker 镜像上。

脚本

## Packages Installation ##
apt-get update -y && apt-get upgrade -y && apt-get install -qq nginx \
php-json php-xmlrpc php-xml php-soap php-fpm php-mysql php-mbstring \
mariadb-server \
wordpress \
vim wget
###########################

# wget https://files.phpmyadmin.net/phpMyAdmin/4.9.0.1/phpMyAdmin-4.9.0.1-all-languages.tar.gz
# tar -xzvf phpMyAdmin-4.9.0.1-all-languages.tar.gz

## Apache2 Removal ##
apt-get remove --purge apache2 -y
#####################

# SSL Configuration ##
service mysql start
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout \
/etc/ssl/private/nginx-selfsigned.key -out /etc/ssl/certs/nginx-selfsigned.crt \
-subj "/C=BE/ST=BRUSSELS CITY/L=Brussels/O=19 Coding School/OU=Lacollar/CN=172.17.0.2/[email protected]"
openssl dhparam -out /etc/nginx/dhparam.pem 2048
#snippets creation
#conf file editing
######################

## PHP Processor Configuration on Nginx ##
# mv /var/www/example.com /var/www/example.com.bak
mkdir /var/www/example.com
cp /var/www/html/index.nginx-debian.html var/www/example.com/index.nginx-debian.html
chown -R $USER:$USER /var/www/example.com
#copy example onto sites-available
chmod 755 /etc/nginx/sites-available/example.com
ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled
nginx -t
##########################################

# ## phpMyAdmin Installation ##
rm /phpMyAdmin-4.9.0.1-all-languages.tar.gz
# mkdir /usr/share/phpMyAdmin
mv /phpMyAdmin-4.9.0.1-all-languages /usr/share/phpMyAdmin
mv /usr/share/config.inc.php /usr/share/phpMyAdmin/
#save config.sample, copy config
mysql < /usr/share/phpMyAdmin/sql/create_tables.sql -u root
mysql -u root -e "GRANT ALL PRIVILEGES ON phpmyadmin.* TO 'pma'@'localhost' IDENTIFIED BY 'pmapass'"
mysql -u root -e "FLUSH PRIVILEGES"
#copy phpmyadmin.conf onto /etc/nginx/conf.d
mkdir /usr/share/phpMyAdmin/tmp
chmod 777 /usr/share/phpMyAdmin/tmp
chown -R www-data:www-data /usr/share/phpMyAdmin
mysql -u root -e "CREATE DATABASE app_db"
mysql -u root -e "GRANT ALL PRIVILEGES ON app_db.* TO 'app_user'@'localhost' IDENTIFIED BY 'password'"
mysql -u root -e "FLUSH PRIVILEGES"
# #############################

# IP Address display
ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'

rm /tmp/configuration.sh

由于我认为问题可能不是出在 PHP 上,而是出在其他方面,所以我还尝试设置 phpMyadmin(然后重新启动 nginx)。我无法访问它,这让我认为问题出在 PHP 上。

非常感谢您的帮助。

相关内容