Jump to content

Nginx Httprewrite


cloudrck

Recommended Posts

Nginx has a system similar to Apaches mod_rewrite, while at the same time being completely different. It's also very robust, with the ability to use Perl or any other scripting language.

 

 

This would go in the server{} area for your particular domain. Of course, there are more than one way to achieve rewriting for Blesta with Nginx, but I think this is the most efficient, and avoids the evil IF-IS many people use with Nginx configurations.

 

If anybody is interested, there are loads of other settings that I use to speed Blesta up, which I'm still working on at the moment.

 

To make it easier to update https://github.com/cloudrck/blesta-nginx

 

location ~ (\.pdt) { 
return 403; 
}
location / {
  error_page     404 = @blesta;
  log_not_found  off;
if ($request_uri ~ "^(.*)/install.php$"){
    rewrite install.php /%1/install/ redirect;
  }
}
 
location @blesta {
  rewrite ^(.*)$ /index.php last; 
}
Link to comment
Share on other sites

Nginx has a learning curve when coming from Apache. A handful of the default configurations of PHP/FCGI from vendors don't go so well with Nginx. As with SSL, I found Nginx will want to start the handshake from scratch each page load. And the stock FPM Process Management settings are set very low.

 

I'll post a lot more soon.

 

I only use PHP-FPM at the moment, rather than plain CGI. As I think it's a much better process manager

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 months later...

Been sorting out a few Nginx Issues as well - especially around forcing everything to use https If you need a hand generating your CSR and a self-signed cert for testing I think I have a guide somewhere as well.

 

My stack where blesta is installed is a centminmod install, and then I just added a vhost where I installed Blesta in the root.

 

My complete sanitized vhost config file is included for reference.

 

server {
  server_name namegoeshere.com;
  access_log /path/to/access.log combined buffer=32k;
  error_log /path/to/error.log;
  root /path/to/docroot;
listen  80;
listen 443 default ssl;
ssl     on;
ssl_certificate         /path to/certificate.crt;
ssl_certificate_key     /path/to/ssl.key;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout  10m;
ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4:HIGH:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!AESGCM;
ssl_prefer_server_ciphers on;
 
# Force All pages to use SSL  
  if ($ssl_protocol = "") {
       rewrite ^   https://$server_name$request_uri? permanent;
    }
 
location ~ (\.pdt) {
return 403;
}
location / {
  error_page     404 = @blesta;
  log_not_found  off;
if ($request_uri ~ "^(.*)/install.php$"){
    rewrite install.php /%1/install/ redirect;
  }
}
location @blesta {
   rewrite ^(.*)$ /index.php last;
}
  include /path/to/php.conf;
}

 

Specific Issue that I had using the centminmod stack was I had to remove the included config file for staticfiles - it sets cache headers for several static files and was causing issues with the navigation in the admin panel (css).  For fine-tuning, I will probably make a copy of this file and remove just the css stuff to keep it all as fast as possible.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...