0

I had been trying the tutorial for docker following this link: http://geekyplatypus.com/dockerise-your-php-application-with-nginx-and-php7-fpm/

However I get stuck on where to display my own index.html in my /code path. Instead ,it displays the page of Welcome to nginx!. All of my files are the same as in the link. My files contained a code folder(inside is my index.html), docker-compose, site.conf where the same as the link.

I had search and try on many ways and couldn't get it to work. Appreciate if someone can point me a direction to proceed.

I am using docker toolbox on windows os.

Provided here is the configuration files for site.conf and docker-compose.yml

#site.conf
server {
    index index.html;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /code;
}

#docker-compose.yml
web:
    image: nginx:latest
    ports:
        - "8080:80"
    volumes:
        - ./code:/code
        - ./site.conf:/etc/nginx/conf.d/site.conf
Jacob
  • 21
  • 6
  • How are you accessing it? `http://php-docker.local` with correctly setup `hosts` file? – Lawrence Cherone Aug 21 '18 at 03:07
  • @LawrenceCherone after I done the steps. I just do normal docker-compose up and visit http://192.168.99.100:8080/ and it showed welcome to nginx. One of the steps that I diff from the site is that I did not include the servername – Jacob Aug 21 '18 at 03:10
  • Thought as much.. the Nginx config is using `server_name php-docker.local;` so its hosts based.. remove that line and set the server to block to default http://nginx.org/en/docs/http/server_names.html – Lawrence Cherone Aug 21 '18 at 03:14
  • Other work arounds, https://stackoverflow.com/questions/9454764/nginx-server-name-wildcard-or-catch-all – Lawrence Cherone Aug 21 '18 at 03:18
  • I removed the line of server_name php-docker.local; on my config file. So, what do you mean by set the server to block to default? – Jacob Aug 21 '18 at 03:24

1 Answers1

0

As the person who wrote the blog post I feel both thrilled and a bit ashamed to see this question

To answer your specific question - you need to do two things:

  1. Forget about php-docker.local. I see that it is no longer in your nginx config, so I guess you should be good
  2. You should change the ./site.conf:/etc/nginx/conf.d/site.conf part in the docker-compose.yml to ./site.conf:/etc/nginx/conf.d/default.conf

These two steps simplify the flow and allow you to access the application on http://localhost:8080/

To see the working version you can go to - https://github.com/mikechernev/dockerised-php and for a better explanation on why these are changed you can read the follow up post - http://geekyplatypus.com/making-your-dockerised-php-application-even-better/

I really hope this will help others that might stumble into similar issues.

Mike Chernev
  • 189
  • 6