docker 中的 NGINX / wordpress 容器在加载时返回 403 错误

问题描述 投票:0回答:1

我在很长一段时间里都遇到了麻烦,无法让我的 docker 设置在 nginx 上运行 WordPress 博客。

我已经在digitalocean上重新安装了droplet并从头开始设置服务器,但我在配置中没有看到任何明显的错误。调用网站时,wordpress 安装页面无法加载。域名指向正确的IP

我检查了完整路径:当我输入retronexus.net/wp-admin/index.php时它确实有效,但当我只输入域本身时则无效。

我创建的 docker-compose 文件:

version : '3'

services:
  db:
    image: mysql:8.0
    container_name: wordpress_db
    restart: unless-stopped
    env_file: .env
    environment:
      - MYSQL_DATABASE=wordpress
    volumes:
      - rn_dbdata:/var/lib/mysql
    command: '--default-authentication-plugin=mysql_native_password'
    # command: mysqld --initialize-insecure --user=mysql
    networks:
      - rn-network

  wordpress:
    depends_on:
      - db
    image: wordpress:6.6.2-fpm-alpine
    container_name: wordpress
    restart: unless-stopped
    env_file: .env
    environment:
      - WORDPRESS_DB_HOST=db:3306
      - WORDPRESS_DB_USER=$MYSQL_USER
      - WORDPRESS_DB_PASSWORD=$MYSQL_PASSWORD
      - WORDPRESS_DB_NAME=wordpress
    volumes:
      - rn_wordpress:/var/www/html
    networks:
      - rn-network

  webserver:
    depends_on:
      - wordpress
    image: nginx:1.27.2-alpine
    container_name: webserver
    restart: unless-stopped
    ports:
      - "80:80"
    volumes:
      - rn_wordpress:/var/www/html
      - ./nginx-conf:/etc/nginx/conf.d
      - certbot-etc:/etc/letsencrypt
    networks:
      - rn-network

  certbot:
    depends_on:
      - webserver
    image: certbot/certbot
    container_name: certbot
    volumes:
      - certbot-etc:/etc/letsencrypt
      - rn_wordpress:/var/www/html
    command: certonly --webroot --webroot-path=/var/www/html --email EMAIL --agree-tos --no-eff-email --staging -d retronexus.net -d www.retronexus.net

volumes:
  certbot-etc:
  rn_wordpress:
  rn_dbdata:

networks:
  rn-network:
    driver: bridge

nginx.conf

# Default server block to handle all unspecified domains and specify it as default. This block returns an 404 error or redirect to different page.
server {
        listen 80;
        listen [::]:80 default_server;
        server_name _;
        return 404;
}

server {        
        # listen on specified ports
    listen 80;
        listen [::]:80;

        # define server names. 
        server_name www.retronexus.net retronexus.net

        # defines the files that will be used as indexes when processing requests to the server.
        index index.php index.html index.htm;

        # root directory for requests to the server. the directory also is created as a mount point at build time for docker
        root /var/www/html;

        # Handle requests to the well-known dir, where certbot will place a temp file to validate that the DNS for the domain resolves to the server. 
        location ~ /.well-known/acme-challenge {
                allow all;
                root /var/www/html;
        }

        # try_files is used to check for files that match individual URI requests. Instead of 404 status as default, control is passed to wordpress index.php file with request arguments
        location / {
                try_files $uri $uri/ /index.php$is_args$args;
        }

        # Handles PHP processing and proxy these requests to the wordpress container. as the wordpress container will be based on php fpm image, also uncluding config options for FastCGI.
        # NGINX requires an independent PHP processor for PHP requests. In this case, these requests will be handled by the PHP-fprm processor thats included with the wordpress image. 
        # FastCGI specific directives, vars and options that will proxy requests to the wordpress app running on the wordpress container, set preferred index for the parsed URI and parse URI requests.
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass wordpress:9000;
                fastcgi_index index.php;
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_param PATH_INFO $fastcgi_path_info;
        }

        # Handle htaccess files since nginx won't serve them. deny-all ensures that htaccess files will never be served to users.
        location ~ /\.ht {
                deny all;
        }

        # ensure that requests to favicon will not be logged
        location = /favicon.ico {
                log_not_found off; access_log off;
        }

        # ensure that requests to robots will not be logged
        location = /robots.txt {
                log_not_found off; access_log off; allow all;
        }

        # turns off logging for static asset requets and and ensures assets being cacheable
        location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
                expires max;
                log_not_found off;
        }
}

我确实在 Digital Ocean 上从头开始设置了所有内容,但我仍然无法访问该网站,并且它返回 403 错误。

wordpress docker nginx
1个回答
0
投票

我相信

./nginx-conf
应该是包含
nginx.conf
文件的目录,而不是文件本身。您可以尝试注释掉
- ./nginx-conf:/etc/nginx/conf.d
行,看看是否可以到达默认的
nginx
主页。如果是,那就是根本原因。 另请检查 docker 日志,例如使用
docker-compose logs
命令来获取更多信息。

© www.soinside.com 2019 - 2024. All rights reserved.