Nginx configuration tips

Last modification: 2014-07-01 16:25:45

Demo install nginx configuration example

# Demo install
    server {
       listen          *:80;
       server_name     demo.livehelperchat.com;
       root           /<path_to_folder>/livehelperchat_demo_com;
       access_log     /var/log/nginx/access_demo_livehelperchat.log main;

       location ~* (^(?!(?:(?!(php)).)*/(albums|bin|var|lib|cache|doc|settings|pos|modules)/).*?(index\.php|upgrade\.php)$) {
          include        /etc/nginx/fastcgi_params;
          fastcgi_pass   127.0.0.1:9000;
          fastcgi_index  index.php;
          fastcgi_param  PATH_INFO          $query_string;
          fastcgi_param  SCRIPT_FILENAME /<path_to_folder>/livehelperchat_demo_com/$fastcgi_script_name;
       }

       #Allow hotlinking to normal and thumb size images
       location ~* (normal_|thumb_|^/design|^/cache|^/var/storagetheme)(.*)\.(gif|jpe?g?|png|mp3|svg|otf|woff|eot|ttf|ogg|wav|bmp|htm|swf|css|js|swf|pdf|ico)$ {
            ## @todo: add expires headers...
            # favicon is only stored in 1 dir, the design one; But browsers ask for it in the root

           if ($http_user_agent ~* "(WebReaper|wget|SiteSucker|SuperBot|Mihov Picture Downloader|TALWinHttpClient|A1 Website Download|WebCopier|Download Ninja|Microsoft URL Control|GetRight|Arachmo|MJ12bot|Gaisbot|Anonymous|Yanga|Twiceler|psbot|Irvine|Indy Library|HTTrack)" ) {
                return 403;
           }

           if ($http_referer ~* (stockingteensex.info|cbox.ws|teensos.net|dpstream.net|tagged.com|kaskus.us|gorilladatingservice.info|taringa.net|discuss.com|craigslist.org|poringa.net)) {
              return 403;
           }

           aio on;
           directio 512;

           expires max;
           access_log        off;
           root           /<path_to_folder>/livehelperchat_demo_com;
       }

       # Do not allow to hotlink full size images except our self and major search engines
       location ~* \.(gif|jpe?g?|png|bmp|swf|css|js|svg|otf|eot|ttf|woff|swf|mp3|ogg|wav|pdf|ico|txt)$ {
            ## @todo: add expires headers...

           valid_referers none blocked server_names ~(livehelperchat.com|google.|reddit.|bing.|yahoo.);
           if ($invalid_referer) {
                 return 403;
           }

           if ($http_user_agent ~* "(WebReaper|wget|SiteSucker|SuperBot|Mihov Picture Downloader|TALWinHttpClient|A1 Website Download|WebCopier|Download Ninja|Microsoft URL Control|GetRight|Arachmo|MJ12bot|Gaisbot|Anonymous|Yanga|Twiceler|psbot|Irvine|Indy Library|HTTrack)" ) {
                    return 403;
           }

           if ($http_referer ~* (stockingteensex.info|cbox.ws|teensos.net|dpstream.net|tagged.com|kaskus.us|gorilladatingservice.info|taringa.net|discuss.com|craigslist.org|poringa.net)) {
              return 403;
           }

           aio on;
           directio 512;

           expires max;
           root           /<path_to_folder>/livehelperchat_demo_com;
       }

       location / {
           rewrite "^(.*)$" "/index.php?$1" last;
       }
    }

Example for subdirectory (not tested by me)

location /lhc_directory {
    try_files $uri $uri/ /lhc_directory/index.php?q=$uri&$args;
}

fastcgi_params file

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;


fastcgi_buffers 256 16k;
fastcgi_max_temp_file_size 0;
fastcgi_buffer_size 64k; ‚Äč

 

Support project

Developing application takes a lot of time. You can support application by donating. There is no company behind this application and it takes away my free time. Every donation matters and does not matter how small it is!


Paypal, one time donation
Monthly donation
Bitcoin
Skrill
remdex@gmail.com


comments powered by Disqus