title: How to route my php server through nginx using docker-compose?
body: <p>This is my first time developing a docker application form scratch. I want to have all my services running from container while I edit the code from my local machine. </p>
  
  <p>So I have a root folder just called <code>test/</code> and i want to follow this tutorial <a href="https://auth0.com/blog/developing-restful-apis-with-lumen/" rel="nofollow noreferrer">https://auth0.com/blog/developing-restful-apis-with-lumen/</a>. So i need composer, a web sever (nginx), and a database (mysql). </p>
  
  <p>I have inside the root folder a docker-compose file as follows:</p>
  
  <pre><code>version: '2'
  
  services:
  
    composer:
      image: composer
      container_name: composer
      volumes:
        - ./authors:/app
      restart: always
      tty: true
      command: bash
  
    php:
      image: php:fpm
      container_name: php
      restart: always
      tty: true
      working_dir: /var/www
      volumes:
        - ./authors:/var/www
      environment:
        - "DB_PORT=3306"
        - "DB_HOST=mysql"
  
    nginx:
      image: nginx
      container_name: nginx
      restart: always
      tty: true
      working_dir: /var/www
      volumes_from:
        - php
      volumes:
        - ./vhost.conf:/etc/nginx/conf.d/default.conf
      ports:
        - 8080:80
  
    mysql:
      image: mysql:5.7
      container_name: mysql
      restart: always
      tty: true
      ports:
        - "3306:3306"
      environment:
        MYSQL_DATABASE: hmh
        MYSQL_USER: root
        MYSQL_ROOT_PASSWORD: root
      volumes:
        - dbdata:/var/lib/mysql
  
  #Volumes
  volumes:
    dbdata:
  </code></pre>
  
  <p>And here is the configuration file used for nginx:</p>
  
  <pre><code>server {
      listen 80;
      index index.php index.html;
      root /var/www/public;
  
      location / {
          try_files $uri /index.php?$args;
      }
  
      location ~ \.php$ {
          fastcgi_split_path_info ^(.+\.php)(/.+)$;
          fastcgi_pass php:8000;
          fastcgi_index index.php;
          include fastcgi_params;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          fastcgi_param PATH_INFO $fastcgi_path_info;
      }
  }
  </code></pre>
  
  <p>The composer container is there so that I can jump into anytime I need and run some commands, while also being able to lift the project from it by running <code>php -S localhost:8000 -t public</code> this actually logs into the console that the server is running BUT when I go into localhost:8080 it is only showing the nginx welcome screen.</p>
  
  <p>So I know nginx is working, composer lets me do all the work I need, but how do I route the php server through nginx? I can go inside the container of php, and start the server but when go to the URL it does not work. If it is not much to ask, I would like some explanation and not just the solution. Thanks.</p>