Score:0

docker-compose: I can't access css and js files of wordpress

cn flag

NOTE: I posted this question in stackoverflow too

I'm trying to set up WordPress using docker-compose but WordPress has to work in a separated container with php_fpm, a container for MariaDB, and an Nginx in port 443 redirecting to WordPress if the link was HTTPS://localhost/wordpress but if the link was HTTPS://localhost/ it has to send the request to index.html page on the same container.

everything works fine but I have a problem with WordPress CSS and js files.

the file returns a 403 (forbidden) error code when the browser tries to get them

my 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" ]

default.conf

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 dockerfile:

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" ]

in flag
Please provide the rest of your configuration (nginx, WordPress, Dockerfiles)
DarkSide77 avatar
cn flag
@GeraldSchneider done I added them
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.