[SOLVED] Nginx, Spip rewrite rules, and robots.txt

Discussion in 'Installation/Configuration' started by mpellegrin, Oct 23, 2017.

  1. mpellegrin

    mpellegrin New Member

    Hello,

    I can't get the Spip robots.txt to work with ISPConfig, it seems that the default "location = /robots.txt" block is superseeding my configuration, and returns a 404, because the file does not exists.

    Here are my rewrite rules for Spip, set in the Options tab :
    Code:
    location / {
    
       try_files $uri $uri/ /spip.php?q=$uri&$args;
    
       # standard files
       rewrite ^/robots\.txt$  /spip.php?page=robots.txt  last;
       rewrite ^/favicon\.ico$  /spip.php?page=favicon.ico  last;
       rewrite ^/sitemap\.xml$  /spip.php?page=sitemap.xml  last;
    }
    
      location ~* \.(pdf|tif|eps|ai|xls|xlsx)$ {
      types {
      application/octet-stream .pdf;
      application/octet-stream .tif;
      application/octet-stream .eps;
      application/octet-stream .ai;
      application/octet-stream .xls;
      application/octet-stream .xlsx;
      }
      default_type application/octet-stream;
      }
    
    And here is the written vhost, that ISPConfig produces :
    Code:
    server {
            listen *:80;
            listen [::]:80;
    
            listen *:443 ssl;
    		ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
            listen [::]:443 ssl;
            ssl_certificate /var/www/clients/client1/web4/ssl/xxxx.com-le.crt;
            ssl_certificate_key /var/www/clients/client1/web4/ssl/xxxx.com-le.key;
    
            server_name xxxx.com www.xxxx.com;
    
            root   /var/www/xxxx.com/web/;
    
            if ($http_host ~* "^(xxxx\.com|((?:\w+(?:-\w+)*\.)*)((?!www\.)\w+(?:-\w+)*)(\.xxxx\.com))$") {
                rewrite ^ $scheme://www.xxxx.com$request_uri? permanent;
            }
            if ($scheme != "https") {
                rewrite ^ https://$http_host$request_uri? permanent;
            }
    
    
            index index.html index.htm index.php index.cgi index.pl index.xhtml;
    
    
    
            error_log /var/log/ispconfig/httpd/xxxx.com/error.log;
            access_log /var/log/ispconfig/httpd/xxxx.com/access.log combined;
    
            location ~ /\.(?!well-known/acme-challenge/) {
                deny all;
                access_log off;
                log_not_found off;
            }
    
            location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
            }
    
            location = /favicon.ico {
                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/client1/web4/web/stats/.htpasswd_stats;
            }
    
            location ^~ /awstats-icon {
                alias /usr/share/awstats/icon;
            }
    
            location ~ \.php$ {
                try_files /xxxx.htm @php;
            }
    
            location @php {
                try_files $uri =404;
                include /etc/nginx/fastcgi_params;
                fastcgi_pass unix:/var/lib/php5-fpm/web4.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_intercept_errors on;
            }
    
    
            location / {
    
            	try_files $uri $uri/ /spip.php?q=$uri&$args;
    
            	rewrite ^/robots\.txt$    /spip.php?page=robots.txt    last;
            	rewrite ^/favicon\.ico$   /spip.php?page=favicon.ico   last;
            	rewrite ^/sitemap\.xml$   /spip.php?page=sitemap.xml   last;
            }
    
            location ~* \.(pdf|tif|eps|ai|xls|xlsx)$ {
                    types {
                        application/octet-stream .pdf;
                        application/octet-stream .tif;
                        application/octet-stream .eps;
                        application/octet-stream .ai;
                        application/octet-stream .xls;
                        application/octet-stream .xlsx;
                    }
                    default_type application/octet-stream;
            }
    
            location ~ /\.well-known/acme-challenge/ {
    	   root /usr/local/ispconfig/interface/acme/;
    	   index index.html index.htm;
    	   try_files $uri =404;
            }
    }
    
    As a temporary fix, I patched the file /usr/local/ispconfig/server/conf/nginx_vhost.conf.master to remove the "location =" block, but is there a better solution ?
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    Add this at the beginning of the nginx directives field:

    Code:
    location = /robots.txt { ##delete##
    }
    
    You can find more examples on merging and removing blocks in nginx config in the ISPCpnfig manual.
     
  3. mpellegrin

    mpellegrin New Member

    Thanks till :)

    I have just bought the manual and I will read it extensively, thanks for your time!
     
    till likes this.

Share This Page