paketo-buildpacks / php-web

Apache License 2.0
6 stars 7 forks source link

Nginx Root Location #207

Open mawint opened 2 years ago

mawint commented 2 years ago

Thoughts on adding a location / directives in the default nginx config? I'm not sure how many php applications can use this universally but I had to add one with a *-server.conf file to enable clean urls for Wordpress. We could even make it more dynamic to allow editing of the block.

Example

location / {
  #Wordpress pretty urls
  try_files $uri $uri/ /index.php?$args;

  include {{.AppRoot}}/.nginx.conf.d/*-location.conf;
}

The *-location is placeholder and could be named anything but this location directive turns on clean urls by default and allows users to add additional conf files to add rewrites, additional location directives under the root location, etc.

Of course the try_files portion is only applicable if it can be used universally for all php projects. I know laravel uses a similar try_files to enable clean urls as well.

dmikusa commented 2 years ago

This sounds reasonable and Wordpress is a very common use case. I know our Nginx config is behind our HTTPD config in terms of things "just working", although that's primarily due to .htaccess files with HTTPD. It would still be nice if we could make things like pretty URLs generally work out of the box.

I'm wondering if we should gate this behind a configuration setting though? If so, thoughts as far as default on or default off?

I don't know off-hand how many different PHP frameworks this would work for and if it's present, you can't easily turn it off. If the try_files ... line was behind a config setting, then users could disable that and add their own snippet if the default one doesn't work. I think that would be my preference.

mawint commented 2 years ago

That could work as well.

This is more of an "enhancement" topic so I think exploring options to make it universal to most applications would be ideal. Providing my use case though I currently added an additional *-server.conf file because I knew I needed to in order to enable clean URLs but I'm not sure everyone will know to do that.

But I do think that if a location / block is added to the default config, having the ability to adjust what's under root will be needed. So you could have an option to turn on/off the default try_files ... line and fallback on them providing their own plus any additional subfolder location blocks/rewrites they needed under root.