To connect both projects in the same container using Laradock, you need to configure the Nginx server to handle requests for both frontend.local and api.local domains.
Here are the steps to follow:
-
Open the Laradock folder in your project.
-
Locate the
nginx/sitesdirectory and open thedefault.conffile. -
Inside the
default.conffile, you will find the server block for the frontend project. Copy this server block and paste it below the existing one. -
Modify the copied server block to handle requests for the api.local domain. Update the
server_namedirective toapi.localand therootdirective to the path of your API project. -
Save the
default.conffile. -
Open your hosts file (located at
/etc/hostson Linux orC:\Windows\System32\drivers\etc\hostson Windows) and add the following entries:
127.0.0.1 frontend.local
127.0.0.1 api.local
- Restart the Laradock containers by running the following command from the Laradock directory:
docker-compose down
docker-compose up -d nginx
Now, you should be able to access both projects using the respective domains. Make sure to update your API code to use the correct domain (api.local) for any API requests.
If you still encounter any issues, ensure that your API project is running on port 80 inside the container and that there are no conflicts with other services running on your local machine.