title: PHP website using Docker and Nginx with subdomains on Raspberry Pi
body: <p>Let's say i own the domain <code>domain.com</code>. I want to host, on my Raspberry Pi 4, a PHP website when I go on the URL <code>domain.com</code>, in parallel with a NextCloud instance when I go to <code>drive.domain.com</code>.</p>
  <p>For this purpose I use Docker and Nginx following this tutorial <a href="https://linuxhandbook.com/nginx-reverse-proxy-docker/#step-5-run-other-service-containers-with-reverse-proxy" rel="nofollow noreferrer">https://linuxhandbook.com/nginx-reverse-proxy-docker/#step-5-run-other-service-containers-with-reverse-proxy</a> where we setup a VIRTUAL_HOST for each subdomain on the network <code>net</code>. I managed to get the Nextcloud instance working on my subdomain <code>drive.domain.com</code>.</p>
  <p>When I try the <code>nginx-dummy</code> example using <code>docker run --rm --name nginx-dummy -e VIRTUAL_HOST=domain.com -e LETSENCRYPT_HOST=domain.com -e VIRTUAL_PORT=80 --network net -d nginx:latest</code>, it seems to work because the url <code>domain.com</code> lands the nginx config page. Unfortunately, I didn't manage to change this html page into my PHP website and get it working on <code>domain.com</code>. Folder being like so:</p>
  <p><a href="https://i.stack.imgur.com/esERp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/esERp.png" alt="enter image description here" /></a></p>
  <p>I tried to create a <code>docker-compose.yml</code> with Nginx and PHP like so:</p>
  <pre><code>version: '3'
  services:
   # Nginx server configuration
    web:
      image: nginx:latest
      container_name: webserver
      environment:
        VIRTUAL_HOST: 'domain.com'
        VIRTUAL_PORT: 80
      depends_on:
        - php
      links:
        - php
      volumes:
        - ./webcontent:/var/www/html
        - ./nginx:/etc/nginx/conf.d/
   # Php-fpm configuration
    php:
      image: php:7.2-fpm
      volumes:
        - ./webcontent:/var/www/html
        - ./php:/usr/local/etc/php/php.ini
  </code></pre>
  <p>but it did not work, returning <code>502 Bad Gateway</code>.</p>
  <p>Also, Let's encrypt certificates don't seem to be working. Maybe for another question though.</p>
  <p>Would you have an idea how to proceed?</p>