在 Nginx 上運行 PHP 頁面的 404

在 Nginx 上運行 PHP 頁面的 404

我對伺服器相當陌生,正在使用 Nginx 設定我的第一個 Web 伺服器PHPMyadmin(以及 SSL 和 Wordpress)。我正在開發的作業系統是一個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 中。

感謝每一個幫助。

相關內容