Here are the steps to edit the Nginx configuration file in Laravel Forge for subdomains:
1. Create the Subdomain in Laravel Forge:
- Log in to your Laravel Forge account.
- Navigate to the "Sites" section.
- Click on the site you want to configure.
- Click on the "Subdomains" tab.
- Create the subdomain you want to use (e.g., `staging.mysite.com`, `api.mysite.com`).
2. Edit the Nginx Configuration:
- In the "Nginx" tab, click on the "Edit" button.
- Update the Nginx configuration to include the subdomain:
nginx
server {
listen 80;
server_name staging.mysite.com;
root /var/www/laravel_project/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?_share=++;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
}
- Repeat this process for each additional subdomain you want to configure.
3. Configure DNS:
- In your DNS provider (e.g., AWS Route 53), create A records for each subdomain pointing to the IP address of your server.
4. Test the Subdomains:
- Visit each subdomain (e.g., `staging.mysite.com`, `api.mysite.com`) to ensure they are working as expected.
The key steps are:
1. Create the subdomain in Laravel Forge.
2. Edit the Nginx configuration to include the subdomain.
3. Configure the DNS records to point the subdomain to your server.
4. Test the subdomains to ensure they are working correctly.
By following these steps, you can edit the Nginx configuration file in Laravel Forge to set up and manage subdomains for your Laravel application.
Citations:[1] https://laravel.io/forum/10-09-2015-two-subdomains-pointing-to-same-location-in-forge
[2] https://laracasts.com/discuss/channels/forge/forge-how-to-change-the-default-nginx-configuration
[3] https://stackoverflow.com/questions/76204387/laravel-forge-no-such-file-directory-in-edit-nginx-configuration
[4] https://forge.laravel.com/docs/sites/the-basics.html
[5] https://stefanzweifel.dev/posts/2019/01/22/include-and-version-nginx-configs-in-laravel-forge/