Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

website-specific custom nginx best practices? #367

Closed
vesper8 opened this issue Apr 30, 2017 · 5 comments
Closed

website-specific custom nginx best practices? #367

vesper8 opened this issue Apr 30, 2017 · 5 comments

Comments

@vesper8
Copy link

vesper8 commented Apr 30, 2017

I'm switching from Homestead to Valet and mostly it's been very smooth but running into a few issues. I have a few sites I'm working on that require custom nginx.

One requires this block (Invision Board Forum)

    location /api/ {
        if (!-e $request_filename){
            rewrite ^/api/(.*)$ /api/index.php;
        }
    }

Another requires these (to possibly replace existing location / block)

    location / {
        try_files $uri $uri/ /index.php;
        if (-f $request_filename){
                set $rule_0 1$rule_0;
        }
        if ($rule_0 = "1"){
            #ignored: "-" thing used or unknown variable in regex/rew
        }

        rewrite ^/login/?$ /login.php last;
        rewrite ^/register/?$ /register.php last;
        rewrite ^/recover/?$ /recover.php last;
        rewrite ^/people/?$ /people.php last;
        rewrite ^/people/([0-9]+)$ /people.php?p=$1 last;
        rewrite ^/messages/?$ /messages.php last;
        rewrite ^/friends/?$ /friends.php last;
        rewrite ^/requests/?$ /friends.php?tab=requests last;
        rewrite ^/requests/([0-9]+)/accept$ /friends.php?tab=requests&accept=true&id=$1 last;
        rewrite ^/requests/([0-9]+)/decline$ /friends.php?tab=requests&decline=true&id=$1 last;
        rewrite ^/user/([0-9]+)$ /profile.php?id=$1 last;
        rewrite ^/user/([0-9]+)/photos$ /profile.php?id=$1&tab=photos last;
        rewrite ^/user/([0-9]+)/friends$ /profile.php?id=$1&tab=friends last;
        rewrite ^/user/([0-9]+)/about$ /profile.php?id=$1&tab=about last;
        rewrite ^/user/([0-9]+)/photo_upload$ /profile.php?id=$1&photo_upload=true last;
        rewrite ^/me/customize$ /customize_profile.php last;
        rewrite ^/messages/([0-9]+)$ /messages.php?id=$1 last;
        rewrite ^/message/([0-9]+)$ /messages/$1 last;
        rewrite ^/messages/([0-9]+)/delete$ /messages.php?id=$1&delete=true last;
        rewrite ^/messages/([0-9]+)/unblock$ /messages.php?id=$1&unblock_user=true last;
        rewrite ^/page/([0-9]+)$ /page.php?id=$1 last;
        rewrite ^/settings/?$ /settings.php last;
        rewrite ^/likes/?$ /likes.php last;
        rewrite ^/visitors/?$ /visitors.php last;
        rewrite /quickmatch/?$ /quickmatch.php last;
        rewrite ^/upgrades/?$ /upgrades.php last;
    }

and yet another requires this inside the location ~ .php$ block

fastcgi_buffers 16 16k; 
fastcgi_buffer_size 32k;

With Homestead I simply had a little script that would be triggered by the after.sh which just took my custom nginx configurations and overwrote whatever ones the homestead provisioning script had created

With Valet I'm not at all sure how to go about doing this as it's not clear how nginx is involved.. I don't see unique nginx vhost files created for all my linked domains

Would really appreciate some guidance!

@adamwathan
Copy link
Contributor

The way this is done in Valet is using custom drivers:

https://laravel.com/docs/5.4/valet#custom-valet-drivers

Valet uses one nginx config for the whole environment, all of the actual rewrite rules for a project exist in PHP.

Here's the rules for a Laravel project for example:

https://github.com/laravel/valet/blob/master/cli/drivers/LaravelValetDriver.php

@vesper8
Copy link
Author

vesper8 commented May 1, 2017

alright.. that's a bit confusing how to translate nginx rewrite rules to php but I think I'll figure it out by looking at the other drivers

but what if i want to apply specific CORS settings for a site? I have to apply it to ALL sites?

@adamwathan
Copy link
Contributor

If you want to manage all your nginx configuration and stuff yourself you are better off just using nginx directly, you won't really be getting any benefit from using Valet at all.

Usually CORS settings are done in code at the app level, not at the server configuration level.

@kerns
Copy link

kerns commented Mar 7, 2019

The way this is done in Valet is using custom drivers:

https://laravel.com/docs/5.4/valet#custom-valet-drivers

Valet uses one nginx config for the whole environment, all of the actual rewrite rules for a project exist in PHP.

Here's the rules for a Laravel project for example:

https://github.com/laravel/valet/blob/master/cli/drivers/LaravelValetDriver.php

Just wondering if this approach ever changed, or was updated or augmented since 2017? Like @vesper8 I also think it would be sooo helpful to just have a _nginx.conf some place easily accessible in these cases where an application requires a specific tweak.

@mar627
Copy link

mar627 commented Aug 6, 2019

Absolutely, be nice to test things like error page redirects or post max data sizes per site locally within valet!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants