index.php在访问WordPress页面时被下载,在Docker上运行

4zcjmb1e  于 2023-11-17  发布在  Docker
关注(0)|答案(1)|浏览(125)

第一次尝试Docker(与docker-compose)和我的问题是,虽然使用像http://localhost/wordpress/sample-post而不是http://localhost/wordpress/?p=123的permalink结构,当访问页面链接时,http://localhost/index.php文件试图被下载。它甚至不是/wordpress/文件夹内的文件,它会转到根级别(也尝试访问WordPress作为根级别,行为是相同的)。
有吨类似的问题在那里,但应该我有正确的配置设置。
可能是什么原因造成的?
我的配置:

compose.yaml

services:
  nginx:
    image: nginx:latest
    ports:
      - 80:80
    volumes:
      - ./nginx.conf:/etc/nginx/conf.d/default.conf
      - C:/dev:/var/www/html 

  php:
    build:
      context: .
      dockerfile: php.Dockerfile
    volumes:
        - ./php.ini:/usr/local/etc/php/conf.d/php.ini
        - C:/dev:/var/www/html

  mysql:
    image: mysql:latest
    command: --default-authentication-plugin=mysql_native_password
    environment:
      - MYSQL_ROOT_PASSWORD=root
    ports:
      - 3306:3306

字符串

nginx.conf

server {
    listen 80;
    server_name localhost;
    root /var/www/html;

    error_log /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;

    index index.php index.html index.htm;
    autoindex on; # to enable directory listing 

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

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_param HTTP_PROXY ""; # Mitigate https://httpoxy.org/ vulnerabilities
        fastcgi_pass php:9000;      
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

php.Dockerfile

FROM php:fpm
RUN docker-php-ext-install mysqli pdo pdo_mysql

php.ini

date.timezone=Europe/London
max_execution_time=120
upload_max_filesize=40M
post_max_size=40M
error_reporting=E_ALL & ~E_DEPRECATED & ~E_STRICT

nfs0ujit

nfs0ujit1#

经过一番挖掘,这部分:

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

字符串
应改为:

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

location /wordpress/ {
    try_files $uri $uri/ /wordpress/index.php?$args;
}


考虑到我有我的WordPress在一个子文件夹。index.php?$args部分也很重要,它可以正常工作。
我不确定这是不是最优雅的解决方案,但这就是我现在所拥有的。

相关问题