0

I'm trying to run MyBB forum software with Docker to run it on my server where I already have NGINX running serving other content.

This is how my docker-compose.yml currently looks like (I've been changing and testing stuff for a while now...):

services:
  mybb:
    image: mybb/mybb:latest
    volumes:
    - ${PWD}/mybb:/var/www/html:rw
    ports:
      - "9000:9000"

  postgresql:
    environment:
      POSTGRES_DB: mybb
      POSTGRES_PASSWORD: password
      POSTGRES_USER: mybb
    image: postgres:13.2-alpine
    volumes:
    - ${PWD}/postgres/data:/var/lib/postgresql/data:rw

version: '3.7'

And this is how the NGINX config file for this specific domain looks like:

upstream mybb {
    server 172.20.0.2:9000 weight=5;
}

server {
    listen 80;
    listen [::]:80;

    root /home/lobo/mybb_docker/mybb;
    index index.html index.php;

    server_name mydomain.com www.mydomain.com;

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

    location ~ inc/ {
        internal;
    }

    location ~ ^/(images|cache|jscripts|uploads)/ {
        access_log off;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass mybb;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

I've been changing stuff here also... I've tried different IP addresses: 127.0.0.1:9000, 0.0.0.0:9000...

But I'm not able to get it to work. When I access the website it simply returns: File not found.

Is there something I'm clearly doing wrong? Or anything else I can try?

Thank you!!

EDIT: adding /var/log/nginx/error.log:

2021/04/09 10:04:56 [error] 19714#19714: *3705 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: xx.xx.xx.xx, server: mydomain.com, request: "GET / HTTP/1.1", upstream: "fastcgi://172.20.0.2:9000", host: "www.mydomain.com"
JV Lobo
  • 3
  • 4
  • Why making things more difficult with docker? – Gerard H. Pille Apr 09 '21 at 03:10
  • What do you mean by "more difficult"? With those Dockers containers, I don't need to mess around on the server installing PHP/FPM and PostgreSQL. Just need to quickly put together a docker-compose and launch it. – JV Lobo Apr 09 '21 at 07:39
  • Please show exact line from nginx log and do not rephrase it, thx. – Jiri B Apr 09 '21 at 09:35
  • I've edited the question, adding the line of error.log from Nginx – JV Lobo Apr 09 '21 at 10:07
  • You certainly don't need to mess around, you'll find out that docker will do that for you once you run out of disk space. And what do you call "quickly"? Anyways, is anything inside the container listening on port 9000? – Gerard H. Pille Apr 09 '21 at 11:38
  • I understand you don't love Docker hehe. I call "quickly" to create a docker-compose.yml file, do docker-compose up, point an Nginx config file to serve the files from the docker and if everything goes well I have everything running in ~5min. I can test whatever I need to test on the server, then turn off docker and remove the containers, and "nothing happened". Obviously, this is not working so it is no "quickly" anymore. This task is also for me to learn a bit more about how Docker works. If I add an Nginx container and share the volume of the PHP container it actually works. – JV Lobo Apr 09 '21 at 12:11
  • I'm afraid that "nothing happened" is an understatement. In fact so much happened that I stopped using containers. Concerning your problem, could SCRIPT_FILENAME and PATH_INFO be invalid when used inside the container? The directory structure as seen by the container may differ from what it is on the host running Nginx. – Gerard H. Pille Apr 10 '21 at 00:25
  • Right on point. That was it! I had to replace `$document_root` with the right path inside the container (`/var/www/html`) Thanks a lot. Feel free to add that as an answer so I can accept it as the solution :) – JV Lobo Apr 10 '21 at 09:08
  • sorry, was away from keyboard for a while. – Gerard H. Pille Apr 19 '21 at 05:08

1 Answers1

0

The directory structure as seen by the container may differ from what it is on the host running Nginx, making SCRIPT_FILENAME and PATH_INFO invalid.

Gerard H. Pille
  • 2,469
  • 1
  • 12
  • 10
  • That is right. I had to replace `$document_root` with the right path inside the container (`/var/www/html`). Thanks :) – JV Lobo Apr 19 '21 at 10:14