eugene-khyst / letsencrypt-docker-compose

Set up Nginx and Let’s Encrypt in less than 3 minutes with a Docker Compose project that automatically obtains and renews free Let's Encrypt SSL/TLS certificates and sets up HTTPS in Nginx for multiple domain names. Configuration is done using a simple CLI tool.
Apache License 2.0
473 stars 218 forks source link

html/${domain} directory not mounting static content to container (Solution: index.htm is case sensitive) #51

Closed James-P-Bennett closed 1 year ago

James-P-Bennett commented 1 year ago

Hi, got everything working fine, however I'm having trouble getting my content on the container. Before setup I had placed my static html files into /home/user/letsencrypt-docker-compose/html/mysite.com, and I have a valid index.html file inside. When attempting to access my site I see it's directing traffic to the right place and the certificate is valid but I am met with a 403 Forbidden Error. I checked docker compose logs and saw the following: [error] 10#10: *51 "/var/www/html/**mysite.com**/index.html" is forbidden (13: Permission denied), client: **IP**, server: **DOMAIN**, request: "GET / HTTP/1.1", host: "**HOST**"

Based on my understanding, it appears that I may have placed my static content in an incorrect location or there may be some other issue that I am not aware of. I would greatly appreciate any guidance you may be able to provide on the matter. Thank you in advance for your assistance.

P.S. What would be the recommended way to update static content in the future?

eugene-khyst commented 1 year ago

Hi, @Hazmadd. This "/var/www/html/**mysite.com**/index.html" is forbidden (13: Permission denied) looks like a problem with file or directory permissions that can be fixed with chown.

Run the following command and share the output (replace {{domain}} with the real domain name):

docker compose exec nginx sh -c 'echo "$(id -u):$(id -g)"'
docker compose exec nginx ls -la /var/www/html/
docker compose exec nginx ls -la /var/www/html/{{domain}}

P.S. What would be the recommended way to update static content in the future?

Static content is mounted from the host machine to simplify the update of the content. Thus, just edit the files in the way you prefer. The content of this directory is not in the .gitignore, so you can check the content to Git. Update on a laptop push to Git, pull the updates on the server and that's it. No need to restart or reload Nginx.

James-P-Bennett commented 1 year ago
docker compose exec nginx ls -la /var/www/html/

For /html dir: ~/letsencrypt-docker-compose$ sudo docker compose exec nginx ls -la /var/www/html/ total 12 drwxr-xr-x 3 1000 1000 4096 Mar 28 00:24 . drwxr-xr-x 4 root root 4096 Mar 28 00:31 .. -rw-r--r-- 1 1000 1000 0 Mar 28 00:24 .gitkeep drwxr-xr-x 3 1000 1000 4096 Mar 28 00:24 mysite.com

For html/{{domain}}: ~/letsencrypt-docker-compose$ sudo docker compose exec nginx ls -la /var/www/html/mysite.com total 24 drwxr-xr-x 3 1000 1000 4096 Mar 28 00:24 . drwxr-xr-x 3 1000 1000 4096 Mar 28 00:24 .. drwxr-xr-x 2 1000 1000 4096 Mar 28 00:24 Img -rw-r--r-- 1 1000 1000 861 Mar 28 00:24 Index.html -rw-r--r-- 1 1000 1000 1653 Mar 28 00:24 scripts.js -rw-r--r-- 1 1000 1000 1398 Mar 28 00:24 styles.css

James-P-Bennett commented 1 year ago

Tried also running 777 for chmod and still am getting error

eugene-khyst commented 1 year ago

@Hazmadd, you have Index.html (with the uppercase I) instead of index.html. Rename it mv Index.html index.html .

James-P-Bennett commented 1 year ago

@Hazmadd, you have Index.html (with the uppercase I) instead of index.html. Rename it mv Index.html index.html .

Well, that was it. I appreciate you bringing that up. Usually I catch that sort of mistake early