Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Serve HTML Files from a Nginx Server Using Docker

Problem

I have a Nginx container running in docker. It's configured to listen to port http://localhost:80 . When I type the url to my browser I get the following...

Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org. Commercial support is available at nginx.com.

Thank you for using nginx.

Cont'd of Problem

I want nginx to serve my html files from my public directory. Please take a look at my project images...

Project Images:

Project directory

Nginx Container Running

What I have done

  1. Ran the following docker command from my public directory...

    • $ docker run -d --name chat-web -v $PWD:/var/www -p 80:80 nginx
  2. Search for the location of nginx server from /usr/local/bin , /usr/private/var so that I can modify nginx.conf as described in the following post NGinx Default public www location?. I was unable to find the location of the nginx server.

Thanks in advance for taking the time to answer my question. I really appreciate you.

like image 304
Uchenna Avatar asked Nov 30 '17 21:11

Uchenna


People also ask

How do I serve a static file in nginx Docker?

Serving Static Files To deploy the container, use Docker Compose. The Docker Compose output. Your static folder and all of its contents are now being served at http://localhost:8080/ using Nginx running inside Docker. Our static files being served on port 8080.


Video Answer


1 Answers

The default directory that static assets are served out of is /usr/share/nginx/html, not /var/www in the Official NGINX Docker image.

With that said, you're also mapping your entire root directory and not the /public/ folder where your folder contents live - unless of course you're running this from that directory on a pre-build image.

You'll probably want something like:

➜  docker run -p 80:80 -v $(pwd):/usr/share/nginx/html nginx
like image 91
TJ Biddle Avatar answered Oct 28 '22 20:10

TJ Biddle