It seems like your Nginx is not able to connect to your Laravel application running with Octane. This could be due to several reasons, but let's go through a checklist to ensure everything is set up correctly.
-
Ensure Octane is running on port 8000: By default, Laravel Octane runs on port 8000, but you should verify this by checking the Octane configuration or the output when it starts.
-
Docker Networking: Since you are using Docker's bridge network, make sure that the containers can communicate with each other. You can test this by entering the Nginx container and using
curlto access the app container:docker exec -it usersite-api-nginx sh curl http://app:8000If you get a response, then networking is not the issue.
-
Nginx Configuration: Your Nginx configuration seems to be correct, but double-check that the
upstream app_containeris pointing to the correct service name defined in yourdocker-compose.yml. -
Volumes: You are mounting the entire codebase into the Nginx container. This is unnecessary since Nginx only needs access to the
publicdirectory. Adjust your volumes to something like this:volumes: - ./public:/var/www/public - ./docker-compose/nginx:/etc/nginx/conf.d -
File Permissions: Ensure that the files within the container are accessible by the user that the Nginx process is running as.
-
Dockerfile: Your Dockerfile is installing dependencies and setting up the environment. Make sure that the
ENTRYPOINTis correctly starting Octane and that there are no errors during the container startup. -
Logs: Check the logs of both the Laravel application and Nginx for any errors that could give you more information about the issue.
-
Port Exposure: Ensure that the port Octane is running on (8000) is exposed in your
appservice indocker-compose.yml. You can do this by adding theexposedirective:services: app: # ... other configurations ... expose: - "8000"
If after going through this checklist you still encounter issues, you might want to simplify your setup and get it running without Docker first to ensure that there are no application-level issues. Once you have confirmed that, you can then dockerize the application again.
Here's a simplified docker-compose.yml example that might help:
version: "3.7"
services:
app:
build:
args:
user: usersite
uid: 1001
context: ./
dockerfile: Dockerfile
image: usersite-api
container_name: usersite-api
restart: unless-stopped
working_dir: /var/www
expose:
- "8000"
networks:
- usersite
nginx:
image: nginx:1.25-alpine
container_name: usersite-api-nginx
restart: unless-stopped
depends_on:
- app
ports:
- 81:80
volumes:
- ./public:/var/www/public
- ./docker-compose/nginx:/etc/nginx/conf.d
networks:
- usersite
networks:
usersite:
driver: bridge
Remember to replace ./public with the correct path to your Laravel application's public directory.