Stop automatic nginx directives

Discussion in 'Installation/Configuration' started by babydunk, Jun 15, 2016.

  1. babydunk

    babydunk Member

    hello

    is their away to stop these directive for selected sites.

    Code:
    location ~ \.php$ {
      try_files /14c2632390fd6ecb82f89d46b5d714e6.htm @php;
      }
    
      location @php {
      try_files $uri =404;
      include /etc/nginx/fastcgi_params;
      fastcgi_pass unix:/var/lib/php5-fpm/web1.sock;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      fastcgi_intercept_errors on;
      }
    i have been battling with this ever since i installed ispconfig.
    the problem is one of the scripts i run needs certian directive to get it running smoothly . now these directive wont work when in the nginx directive snippet section in the website options. because of the above directives.
    so for the past year i have had to comment out the preinstalled directives and place my own by nano /etc/nginx/sites-enabled/100-domain.tld.vhost

    this has been a nightmare for me considering changing one thing in ispconfig and forget to check if the script in mention is still running smoothly. then realising it has been broken for 20 mins. its not ideal :(

    it would be great of their was a switch to just turn off the mentioned directive above.
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    That's the PHP handler, it is required for any site that runs php script and does not has to be removed. I run many sites on nginx and never had to remobve it, so my guess is that you use the nginx directve field wrong e.g you added a second PHP handler which is not nescessary and will cause trouble then.

    Which exact directive did you add to the nginx directives field?
     
  3. babydunk

    babydunk Member

    heres my vhost

    Code:
            ###
            #PageSpeed Settings
            ###
    
            pagespeed on;
            pagespeed FileCachePath /var/ngx_pagespeed_cache;
    
    server {
            listen xx.xx.xx.xx:80;
    
            listen xx.xx.xx.xx:443 ssl;
                    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
            ssl_certificate /var/www/clients/client0/web31/ssl/domian.tld.crt;
            ssl_certificate_key /var/www/clients/client0/web31/ssl/domian.tld.key;
    
            server_name domian.tld www.domian.tld;
    
            root   /var/www/domian.tld/web/;
           
            client_max_body_size 80M;
    
    
            if ($scheme != "https") {
                rewrite ^ https://$http_host$request_uri? permanent;
            }
    
            index index.html index.htm index.php index.cgi index.pl index.xhtml;
    
    
    
    
            error_page 400 /error/400.html;
            error_page 401 /error/401.html;
            error_page 403 /error/403.html;
            error_page 404 /error/404.html;
            error_page 405 /error/405.html;
            error_page 500 /error/500.html;
            error_page 502 /error/502.html;
            error_page 503 /error/503.html;
            recursive_error_pages on;
            location = /error/400.html {
    
                internal;
            }
            location = /error/401.html {
    
                internal;
            }
            location = /error/403.html {
    
                internal;
            }
            location = /error/404.html {
    
                internal;
            }
            location = /error/405.html {
    
                internal;
            }
            location = /error/500.html {
    
                internal;
            }
            location = /error/502.html {
    
                internal;
            }
            location = /error/503.html {
    
                internal;
            }
    
            error_log /var/log/ispconfig/httpd/domian.tld/error.log;
            access_log /var/log/ispconfig/httpd/domian.tld/access.log combined;
    
            location ~ /\.(?!well-known/acme-challenge/) {
                deny all;
                access_log off;
                log_not_found off;
            }
    
            location = /favicon.ico {
                log_not_found off;
                access_log off;
            }
    
            location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
            }
    
            location /stats/ {
    
                index index.html index.php;
                auth_basic "Members Only";
                auth_basic_user_file /var/www/clients/client0/web31/web/stats/.htpasswd_stats;
            }
    
            location ^~ /awstats-icon {
                alias /usr/share/awstats/icon;
            }
    
              set $cache_uri $request_uri;
    
             # POST requests and urls with a query string should always go to PHP
             if ($request_method = POST) {
             set $cache_uri 'null cache';
             }
             if ($query_string != "") {
                   set $cache_uri 'null cache';
             }
    
             # Don't cache uris containing the following segments
             if ($request_uri ~* "(/oc-admin/|/login.php|/oc-(app|cron|login|register|mail).php|oc-.*.php|/feed/|index.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
                   set $cache_uri 'null cache';
             }
    
    
             location / {
                    try_files  $uri /index.php?$args;
             }
    
             location ~ .php$ {
    
                    ##
                    # Fastcgi cache
                    ##
                    set $skip_cache 1;
                    if ($cache_uri != "null cache") {
                    add_header X-Cache-Debug "$cache_uri $cookie_nocache $arg_nocache$arg_comment $http_pragma $http_authorization";
                    set $skip_cache 0;
             }
                    fastcgi_cache_bypass $skip_cache;
                    fastcgi_cache phpcache;
                    fastcgi_cache_key $scheme$host$request_uri$request_method;
                    fastcgi_cache_valid any 8m;
                    fastcgi_cache_bypass $http_pragma;
                    fastcgi_cache_use_stale updating error timeout invalid_header http_500;
    
                    try_files $uri /index.php;
                    include /etc/nginx/fastcgi_params;
                    fastcgi_buffer_size 16k;
                    fastcgi_buffers 32 16k;
                    fastcgi_pass unix:/var/lib/php5-fpm/web31.sock;
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            }
    
            #location ~ \.php$ {
            #    try_files /e1af3623ae892f0ab1ed44f37c706f33.htm @php;
            #}
    
            #location @php {
            #    try_files $uri =404;
            #    include /etc/nginx/fastcgi_params;
            #    fastcgi_buffers 16 16k;
            #    fastcgi_buffer_size 32k;
            #    fastcgi_pass unix:/var/lib/php5-fpm/web31.sock;
            #    fastcgi_index index.php;
            #    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            #    fastcgi_intercept_errors on;
            #}
    
            # Expire rules for static content
    
            # cache.appcache, your document html and data
            location ~* \.(?:manifest|appcache|html?|xml|json)$ {
                      expires -1;
            # access_log logs/static.log; # I don't usually include a static log
            }
    
            # Feed
            location ~* \.(?:rss|atom)$ {
                      expires 1h;
                      add_header Cache-Control "public";
            }
    
            # Media: images, icons, video, audio, HTC
            location ~* \.(?:jpg|woff|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
                      expires 1M;
                      access_log off;
                      add_header Cache-Control "public";
            }
    
            # CSS and Javascript
            location ~* \.(?:css|js)$ {
                      expires 1y;
                      access_log off;
                      add_header Cache-Control "public";
            }
    
            #####
            # PageSpeed module
            ####
            pagespeed on;
    
            pagespeed FileCachePath /var/ngx_pagespeed_cache;
    
            location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
                       add_header "" "";
            }
            location ~ "^/pagespeed_static/" {
    
            }
            location ~ "^/ngx_pagespeed_beacon$" {
            }
    
                        pagespeed MemcachedThreads 1;
                        pagespeed MemcachedServers "localhost:11211";
    
                       pagespeed RewriteLevel CoreFilters;
                        pagespeed EnableFilters collapse_whitespace,remove_comments;
    
            location ~ "^/ngx_pagespeed_static/" {
            }
            location /ngx_pagespeed_statistics {
                    allow 127.0.0.1;
                    deny all;
            }
            location /ngx_pagespeed_global_statistics {
                    allow 127.0.0.1;
                    deny all;
            }
            location /ngx_pagespeed_message {
                    allow 127.0.0.1;
                    deny all;
            }
            location /pagespeed_console {
                    allow 127.0.0.1;
                    deny all;
            }
    
    
    
            location ~ /\.well-known/acme-challenge/ {
               root /usr/local/ispconfig/interface/acme/;
               index index.html index.htm;
               try_files $uri =404;
            }
    
    
            location /oc-admin/ {
                    auth_basic "Members Only";
                    auth_basic_user_file /var/www/clients/client0/web31/web/oc-admin/.htpasswd;
    
                    #location ~ \.php$ {
                    #    try_files /e1af3623ae892f0ab1ed44f37c706f33.htm @php;
                    #}
            }
    
    }
    
     
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    Ok, so my guess was right, you added a second PHP location which is notnecessary and then collides with the base configuration. To fix our config, remove your custom pHP handler and enable the one from ISPConfig again. Then check if the site works, amost all cms will work out of the box then. If you then want to fine tune some fastcgi directives, simply use the merge syntax to add additional settings into the PHP handler from ispconfig.

    Example:

    location @php {##merge##
    set $skip_cache 1;
    if ($cache_uri != "null cache") {
    add_header X-Cache-Debug "$cache_uri $cookie_nocache $arg_nocache$arg_comment $http_pragma $http_authorization";
    set $skip_cache 0;
    }
    fastcgi_cache_bypass $skip_cache;
    fastcgi_cache phpcache;
    fastcgi_cache_key $scheme$host$request_uri$request_method;
    fastcgi_cache_valid any 8m;
    fastcgi_cache_bypass $http_pragma;
    fastcgi_cache_use_stale updating error timeout invalid_header http_500;
    }

    adds the fastcgi cache settings into the PHP handler from ISPConfig.
     
    babydunk likes this.
  5. babydunk

    babydunk Member

    how do i over ride or stop these to directives from being loaded

    they break the site if their is no post on that catagory within the website.

    also it wont let the cache directives save to the vhost. when theyre placed in the php handler. everything fails to save to vhost.
     
  6. till

    till Super Moderator Staff Member ISPConfig Developer

    See page 125 of the ISPVonfig on how to use the ##merge## directive to merge settings and how to use the nginx directives field in general. Beside ##merge##, there is also a new option ##delete## to delete locations.
     
    babydunk likes this.
  7. babydunk

    babydunk Member

    the handler wont save any of my pagespeed directives either.
    it seems to only handle a handful of directives. :(

    is their a limit to what type and the amount of directives the php handler will save.
     
  8. babydunk

    babydunk Member

    no problem :D

    Thanks Till
     
  9. till

    till Super Moderator Staff Member ISPConfig Developer

    No. Your problem means just that the config is not right yet as ispconfig will roll back the complete config if nginx wont start with it.
     
    babydunk likes this.
  10. babydunk

    babydunk Member

    but all the directives work with no prolbem if placed manually. :confused:
    im sure i will get it figured out at the end but atleast the sites running with no errors now from the ispconfig php handler. maybe not as quick as before but will get that sorted just take abit of tinkering.

    this replaces all @php location directives. much better for my needs.
     
  11. babydunk

    babydunk Member

    thanks again Till

    i got it all working now . i had a "location ~ php$ {} " hiding the middle of my directives and i should of knew not to have " pagespeed on; " in the " server {} " settings

    thanks a bunch . you always have the answers. ;)

    Ps; just need to get the out going mail sorted out :confused: but back to the other thread for that :)
     
  12. babydunk

    babydunk Member

    ps: all the data is not viewable on page 124 of the ispconfig manual ver 1.4
     
  13. till

    till Super Moderator Staff Member ISPConfig Developer

    There is no data missing, that's just too much white space. Seems as if the pdf formatter has a problem with the preformatted content
     
    babydunk likes this.
  14. babydunk

    babydunk Member

    just thought to let yous know just incase yous didnt. ;)
     

Share This Page