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

How to correctly add webmail config to Nginx #245

Open
d0dge opened this issue May 3, 2016 · 2 comments
Open

How to correctly add webmail config to Nginx #245

d0dge opened this issue May 3, 2016 · 2 comments

Comments

@d0dge
Copy link

d0dge commented May 3, 2016

This is more of a request for assistance than an issue so apologies if it shouldn't have been posted here. Hopefully someone can help though!

I'm trying to get Rainloop webmail up and running on a server that also hosts a Drupal site. I'm using Perusio's Nginx config.

I basically just want to add a location to handle the path to Rainloop so that the webmail will be accessible via https://example.com/rainloop.

I've added the following just outside the default location block in drupal.conf:

## Webmail handling
# serve static files
location ~ ^/rainloop/(images|javascript|js|css|flash|media|static)/  {
    rewrite        ^ https://$server_name$request_uri? permanent;
    root /usr/share/nginx/;
    expires 30d;
}

location /rainloop {
    root /usr/share/nginx/;
    index index.html index.htm index.php;
    autoindex on;
    autoindex_exact_size off;
    autoindex_localtime on;
}

location ^~ /rainloop/data {
    deny all;
}

It's returning 404 even though the paths are correct. I suspect it's to do with one or both of these locations at the end of the config:

location ^~ /index.php {
    if ( $args ~* "^q=(?<query_value>.*)" ) {
        rewrite ^/index.php$ $scheme://$host/?q=$query_value? last;
    }
    return 404;
}

## Any other attempt to access PHP files returns a 404.
location ~* ^.+\.php$ {
    return 404;
}

How do make an exception to these 404 rules for the rainloop directory?

@emesch
Copy link

emesch commented May 3, 2016

The last regex location will catch any uri that ends in .php, even if it starts with "rainloop". That's because nginx first parses the location prefixes, and then moves on to the location regexes. If you want nginx to skip the regex matching if a certain prefix match is made, use the "^~" modifier. Try:

location ^~ /rainloop {
    ...
}

The nginx location documentation has more details.

Also, don't you need to pass to your php handler?

@d0dge
Copy link
Author

d0dge commented May 3, 2016

Perfect thank you emesch, that did the trick.

Yes you're right, I did need to add my php handler in there too. I've amended the rainloop location to this and it seems to work OK:

 location ^~ /rainloop {
        root /usr/share/nginx/;
        index index.html index.htm index.php;
        autoindex on;
        autoindex_exact_size off;
        autoindex_localtime on;
        fastcgi_pass 127.0.0.1:9000;
        include /etc/nginx/fastcgi.conf;
    }

Is there any reason why I should put the PHP handling in a separate block? Something like:

location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        include fastcgi.conf;
    }

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

2 participants