docker-compose:我无法访问 wordpress 的 css 和 js 文件

docker-compose:我无法访问 wordpress 的 css 和 js 文件

注意:我已将这个问题发布在堆栈溢出

我正在尝试使用 docker-compose 设置 WordPress,但是 WordPress 必须在一个独立的容器中工作,该容器包含 php_fpm、MariaDB 容器和端口 443 中的 Nginx,如果链接存在则重定向到 WordPress,HTTPS://localhost/wordpress但是如果链接存在则HTTPS://localhost/必须将请求发送到同一容器上的 index.html 页面。

一切正常,但我遇到了 WordPress CSS 和 js 文件的问题。

当浏览器尝试获取文件时,文件返回 403(禁止)错误代码

我的docker-compose:

version: '3'
services:
  db:
    image: mysql:5.7
    container_name: mariadb
    volumes:
      - db-data:/var/lib/mysql
    ports:
      - 3306:3306
    environment:
      MYSQL_ROOT_PASSWORD: testadmin
      MYSQL_DATABASE: wordpress
      MYSQL_USER: admin
      MYSQL_PASSWORD: admin
    restart: always
    networks:
      - wpsite
  wordpress:
    build: wordpress/
    volumes:
      - www-data:/var/www/html
    container_name: wordpress
    depends_on:
      - db
    ports: ['9000:9000']
    environment:
      WORDPRESS_DB_HOST: db
      MYSQL_ROOT_PASSWORD: mysql_root_pass
      WORDPRESS_DB_NAME: wordpress
      WORDPRESS_DB_USER: admin
      WORDPRESS_DB_PASSWORD: admin
      WORDPRESS_TABLE_PREFIX: wp_table
    networks:
      - wpsite
    restart: always
  nginx:
    build: nginx/
    image: mynginx:mytest
    container_name: my_nginx
    volumes:
      - www-data:/var/www/html
    ports:
      - 443:443
    depends_on:
      - wordpress
    networks:
      - wpsite

networks:
  wpsite:
volumes:
  db-data:
  www-data:

nginx dockerfile:

FROM  alpine:3.12.0

RUN apk update
RUN apk add nginx openrc vim
RUN apk add php7-common php7-iconv php7-json php7-gd php7-curl php7-xml \
    php7-mysqli php7-imap php7-cgi fcgi php7-pdo php7-pdo_mysql php7-soap php7-xmlrpc \
    php7-posix php7-mcrypt php7-gettext php7-ldap php7-ctype php7-dom php7 php7-fpm php7-opcache openssl

COPY src ./tmp/
RUN mkdir -p /var/www/html/

RUN 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=MA/ST=Khouribga/L=Khouribga/O=1337/CN=ft_services"

RUN mv /tmp/default.conf /etc/nginx/conf.d/
RUN openrc
RUN touch /run/openrc/softlevel

ADD src/run.sh .
RUN chmod +x /run.sh


ENTRYPOINT [ "/run.sh" ]

默认配置文件

server {
    listen                  443 ssl;

    ssl_protocols       TLSv1.3;
    ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
      ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;

    root                    /var/www/html;
    index                   index.html;
    # index                   index.html index.htm index.php;
    server_name             _;
    # client_max_body_size    32m;
    # error_page              500 502 503 504  /50x.html;

    # autoindex off;
    # index index.php index.html index.htm index.nginx-debian.html;

    # include /etc/nginx/mime.types;
    location = /50x.html {
            root              /var/lib/nginx/html;
    }
    location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to displaying a 404.
    index index.html;
    # try_files $uri $uri/ /index.php?$args;
    }
  # pass the PHP scripts to FastCGI server listening on wordpress:9000
    location /wordpress {
    # fastcgi_split_path_info ^(.+\.php)(/.+)$;
    # root  /var/www/html/;
    fastcgi_pass 0.0.0.0:9000;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param SCRIPT_NAME $fastcgi_script_name;
    }
}

WordPress docker文件:

FROM  alpine:3.12.0

RUN apk update
RUN apk add openrc
RUN apk add php7-common php7-iconv php7-json php7-gd php7-curl php7-xml \
    php7-mysqli php7-imap php7-cgi fcgi php7-pdo php7-pdo_mysql php7-soap php7-xmlrpc \
    php7-posix php7-mcrypt php7-gettext php7-ldap php7-ctype php7-dom php7 php7-fpm php7-opcache


COPY src ./tmp/
RUN mkdir -p /var/www/html
RUN openrc
RUN touch /run/openrc/softlevel

RUN sh tmp/wp-setup.sh
ADD src/run.sh .
RUN chmod +x /run.sh


ENTRYPOINT [ "/run.sh" ]

相关内容