Nginx friendly URLs



  • According to the software specifications, you can use Nginx as server.

    But, if you want to activate the URL friendly option in the SEO & URLs tab, you see the following message: 1. Create a blank .htaccess file 2. Give it write permissions.

    I have tried to activate it, but it shows the written message.

    I don’t want to use Apache as a server, since I consider Nginx a better server. So, What is the action to perform to fix this problem?

    Thank you!!



  • Have you tried manually making new nginx redirects?

    https://winginx.com/en/htaccess



  • Not really a bug. For Working with nginx you have to rewrite htaccess rules for nginx. Use tool linked by @the-rampage-rado above :-)



  • Thank you. I just have created the empty .htaccess file that the page tells me, and everything worked fine. It would be great if a better description will appear just to clarify that is necessary to create the file even if you are using nginx.

    By the way. The nginx configuration is the same as Prestashop uses, so, for those who want to use Nginx, you just have to use the same configuration.

    Thank you and regards!! :dancers:


  • administrators

    Let me share my nginx configuration. Btw, it automatically redirects every HTTP request to HTTPS, so make sure you use HTTPS everywhere.

    server {
        listen 80;
        listen [::]:80;
        server_name example.com www.example.com;
    
        # Uncomment when using Let's Encrypt
        #location ~ /.well-known {
        #    allow all;
        #}
    
        ## redirect http to https ##
            rewrite        ^ https://www.example.com$request_uri? permanent;
       }
    
    server {
        listen 443 ssl http2;
        listen [::]:443 ssl http2;
        server_name example.com;
    
        ssl on;
        ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; 
        ssl_prefer_server_ciphers On;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS;
        ssl_session_cache   shared:SSL:10m;
        ssl_session_timeout 10m;
        keepalive_timeout   70;
        add_header 	 Access-Control-Allow-Origin *;
    
        # Uncomment when using Let's Encrypt
        #location ~ /.well-known {
        #    allow all;
        #}
    
          ## redirect non-www to www ##
          rewrite        ^ https://www.example.com$request_uri? permanent;
    }
    
    server {
        listen 443 ssl http2;
        listen [::]:443 ssl http2;
        server_name www.example.com;
        root /var/www/examplecom;
        
        access_log /var/log/nginx/example_com.access.log;
        error_log /var/log/nginx/example_com.error.log;
    
        # Uncomment when using Let's Encrypt
        #location ~ /.well-known {
        #    allow all;
        #}
        
        ssl on;
        ssl_certificate /etc/letsencrypt/live/michaeldekker.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/michaeldekker.com/privkey.pem; 
        ssl_prefer_server_ciphers On;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS;
        ssl_session_cache   shared:SSL:10m;
        ssl_session_timeout 10m;
        keepalive_timeout   70;
        add_header 	 Access-Control-Allow-Origin *;
       
        error_page 405 =200 $uri;
    
        location ~ /.well-known {
            allow all;
        }
    
       index index.php index.html;
    	   
       location = /favicon.ico {
            log_not_found off;
            access_log off;
       }
    
        location = /robots.txt {
            auth_basic off;
            allow all;
             log_not_found off;
             access_log off;
        }
    
        # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
        location ~ /\. {
            deny all;
            access_log off;
            log_not_found off;
       }
    
        # Using CloudFlare for gzip in this case, feel free to change it
        gzip off;
    
        rewrite ^/([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg.webp$ /img/p/$1/$1$2$3.jpg.webp last;
        rewrite ^/([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg.webp$ /img/p/$1/$2/$1$2$3$4.jpg.webp last;
        rewrite ^/([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg.webp$ /img/p/$1/$2/$3/$1$2$3$4$5.jpg.webp last;
        rewrite ^/([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg.webp$ /img/p/$1/$2/$3/$4/$1$2$3$4$5$6.jpg.webp last;
        rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg.webp$ /img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.jpg.webp last;
        rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg.webp$ /img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.jpg.webp last;
        rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg.webp$ /img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.jpg.webp last;
        rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg.webp$ /img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9$10.jpg.webp last;
        rewrite ^/c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg.webp$ /img/c/$1$2$3.jpg.webp last;
        rewrite ^/c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg.webp$ /img/c/$1$2.jpg.webp last;
        rewrite ^/api/?(.*)$ /webservice/dispatcher.php?url=$1 last;
        rewrite ^/([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$1$2$3.jpg last;
        rewrite ^/([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$1$2$3$4.jpg last;
        rewrite ^/([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$1$2$3$4$5.jpg last;
        rewrite ^/([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$1$2$3$4$5$6.jpg last;
        rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.jpg last;
        rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.jpg last;
        rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.jpg last;
        rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9$10.jpg last;
        rewrite ^/c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ /img/c/$1$2$3.jpg last;
        rewrite ^/c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$ /img/c/$1$2.jpg last;
    
        if (!-e $request_filename) {
            rewrite ^/.*$ /index.php last;
        }
    
        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_keep_conn on;
             include /etc/nginx/fastcgi_params;
    	fastcgi_pass backend;			
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param  HTTPS on;
    	fastcgi_read_timeout 60m;
    	fastcgi_send_timeout 60m;
       	fastcgi_buffer_size 128k;
        	fastcgi_buffers 256 16k;
            fastcgi_busy_buffers_size 256k;
            fastcgi_temp_file_write_size 256k;
        }
    }
    


  • where to put this code? I just transferred to Nngix server.
    tks.



  • In the server block that handle your domain



  • If I say this “please put the code in the server block that handles domain” to my hosting support, do you think they will understand?

    I am no coder at all.

    Thanks.



  • Yes, you can tell them that and they will understand.
    Basically they only need the rewrite section.



  • @mdekker , I thought that keepalive was useless with http2 :/


  • administrators

    It’s for http 1.1 clients



  • Oh, you’re right. Didn’t see the config. for the different protocols.



  • Does anyone have config for http 2, 1.1 and 1.0 ?



  • The one that posted mdekker does the trick.



  • I usually load all the ssl certificate + settings once outside the server blocks on top.



  • is there are helpful tricks with http2? adding extra path for CSS etc.?



  • @mdekker may i ask what solution you used to figure out if the sites should deliver a webp vs a jpg file ?


  • administrators

    Let me dig the server for that info. It was used back in 2014, but not very successful. I guess I kept in in the nginx config in case I’d ever try webp again.


  • administrators

    It was some mapping in nginx, if accept = webp, then rewrite to $1.jpg.webp


  • administrators


Log in to reply
 

Looks like your connection to thirty bees forum was lost, please wait while we try to reconnect.