Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

billythekid's avatar

Forge - change new site default nginx config

Could someone point me in the right direction on where to edit the master copy of the nginx config that gets copied/installed for each new site created in Forge?

To clarify I want every new site rolled to have the edited config by default (which of course can still be changed using the Files button in the site in Forge on a site by site basis)

Cheers

0 likes
5 replies
aurawindsurfing's avatar

Hi,

It looks like they use simply /etc/nginx/nginx.conf but also note that each site in its nginx.conf this at the top:

# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/yoursite.com/before/*;

and this at the bottom:

# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/yoursite.com/after/*;

So you can overwrite the default nginx.conf with your own values if you put it at in the after section.

I think this would be the best way to do this and not to touch default forge files.

Hope it helps!

billythekid's avatar

@AURAWINDSURFING - Yeah that would be on a site-by-site basis still. I want every new site rolled to take a particular config setting so would need to manually still add these to the forge-conf/mysite.com/after folder every time. (in which case I could just copy my rule into the site's nginx configuration anyway, the thing I'm trying to avoid)

I'll have a look at the /etc/nginx/nginx.conf file and see if it contains the bit in the middle that gets copied to each site, if so I'll just edit that and it should propagate to all new sites rolled.

Cheers for the direction

aurawindsurfing's avatar

Yeah that should do the trick however might not be working after some forge updates that you do not control. It is always better to use provided ways of doing things ;-)

How many sites will you spin up that it is worth doing it?

Did you try to use: F-Bar?

https://laravel-forge-menubar.com

billythekid's avatar

@AURAWINDSURFING - Yeah I use F-Bar for editing the sites normally. It would be for every single site on that server, it's only used as a staging server and (for now) I just want to add…

    # we don't want this site listed at all
    location = /robots.txt {
       add_header Content-Type text/plain;
       return 200 "User-agent: *\nDisallow: /\n";
    }

…to every single config on that particular server at site spawn time (because I'll forget to manually do this) There are probably about 30 to 40 sites a year or more spun up on that server for us. (yeah I could make an actual robots.txt file but then I need different files on different branches or something, also this is just an example, there may be other things I want to globally change in future)

Other (production) servers I don't care about or any new servers taking on new forge config is cool too.

You're right of course, don't edit core right? Normally I do live by that. Would be nice perhaps if there were another config file loaded by forge but not updated by forge that I could edit and would be pulled in somewhere between before and after site specific configs with 'globals'.

1 like

Please or to participate in this conversation.