Jump to content
  • 0
Stu

Nginx Config

Question

Hi Guys,

 

can some people show me their nginx configs for blesta?

I had it working using the 'try_files $uri' way of doing things, but I reinatlled my server and forgot how I made it work before.

I am currently using a method i found on here elsewhere (thanks to that poster),

but I would like to get back to the 'try_files $uri' method as it was much cleaner and simpler.

 

Here is what i'm currently using...

     location / {
           error_page     404 = @blesta; #IF file doesn't exist
           log_not_found  off;
           }

      location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_connect_timeout 60;
            fastcgi_send_timeout 180;
            fastcgi_read_timeout 180;
            fastcgi_buffer_size 128k;
            fastcgi_buffers 4 256k; #
            fastcgi_busy_buffers_size 256k;
            fastcgi_temp_file_write_size 256k;
            fastcgi_intercept_errors on;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            }

            # Disallow access to any file with .pdt extension
        location ~ (\.pdt) {
            return 403;
            }

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

        #Core rewrite
        location @blesta {
            rewrite ^(.*)$/index.php/(.*) /$1  permanent;
            }
}

 

I remember before I was using something a lot simpler, something like...

 location / {

               try_files $uri $uri/ 

               then the fastcgi_pass stuff

Share this post


Link to post
Share on other sites

6 answers to this question

Recommended Posts

  • 0

Messed with this for a while after posting the question.

I have come up with the following which seems to work....

 

     location / {
            try_files $uri $uri/ /index.php?$args;
            }

      location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_connect_timeout 60;
            fastcgi_send_timeout 180;
            fastcgi_read_timeout 180;
            fastcgi_buffer_size 128k;
            fastcgi_buffers 4 256k; #
            fastcgi_busy_buffers_size 256k;
            fastcgi_temp_file_write_size 256k;
            fastcgi_intercept_errors on;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            }


            # Deny all attempts to access hidden files
            # such as .htaccess, .htpasswd, .DS_Store (Mac).
        location ~ /\. {
            deny all;
            }
            
            # Disallow access to any file with .pdt extension
        location ~ (\.pdt) {
            return 403;
            }
}

 

If anyone wants to add to this please feel free to post.

Share this post


Link to post
Share on other sites
  • 0

This is what I have setup on my Arch box (minus all the fastcgi, security and optimization I have):

 

location / {
    root   /srv/http/blesta.netops.local/public;
    index  index.html index.htm index.php;
    
    autoindex off;
    rewrite ^(.*)$ https://$http_host$request_uri redirect;

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

    if ($request_uri ~ "^(.*)/install.php$") {
        rewrite install.php /%1/install/ redirect;
    }
}

location ~ ^/(.*/)?\.git(/|$) {
    deny all;
}

location ~ \.(pdt)$ {
    deny all;
}

 

-Adam

 

Share this post


Link to post
Share on other sites
  • 0
16 hours ago, Adam said:

This is what I have setup on my Arch box (minus all the fastcgi, security and optimization I have):

 


location / {
    root   /srv/http/blesta.netops.local/public;
    index  index.html index.htm index.php;
    
    autoindex off;
    rewrite ^(.*)$ https://$http_host$request_uri redirect;

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

    if ($request_uri ~ "^(.*)/install.php$") {
        rewrite install.php /%1/install/ redirect;
    }
}

location ~ ^/(.*/)?\.git(/|$) {
    deny all;
}

location ~ \.(pdt)$ {
    deny all;
}

 

-Adam

 

yeah I had similar before.

Give the try_files way a go. It should make a noticable difference in speed.

Using if statements and rewrites is slower because they are read and processed for each request.

Share this post


Link to post
Share on other sites
  • 0
6 hours ago, speed2host said:

Hey good post. But where exactlly should we add this lines? :) Were not all gurus in dev .. i run a Centos 7 on Apache 

 

 

Best Regards

This goes in your nginx config file. If you need further help, ask your technical staff or hire a server management company.

-Adam

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×