CWP - NGINX & Varnish & Apache with PHP-FPM server how to configure Pretty Permalink for WordPress



  • @sandeep said in CWP - Brotli not work and NGINX not start after upgrade of CWP Pro from v0.9.8.906 to CWP Pro v0.9.8.907 even with the last update to CWP Pro v0.9.8.913.:

    glad to know the nginx brotli installation is now fixed

    regarding the nginx template you sent here is for nginx proxy template vhost, I'm assuming Apache is the main server and you need to have .htaccess entry :
    https://wordpress.org/support/article/htaccess/

    If you want to use nginx + php-fpm use this nginx rewrite rule :

        location / {
            try_files $uri $uri/ /index.php?$args;
            location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
                expires     max;
            }
    `
    

    @Automata said in CWP - Brotli not work and NGINX not start after upgrade of CWP Pro from v0.9.8.906 to CWP Pro v0.9.8.907 even with the last update to CWP Pro v0.9.8.913.:

    Hi, you are very very kind, thank you.

    For CWP Pro i use Nginx & Varnish & Apache with PHP-FPM and not have the .htacces.

    You can tell me precisely where I need to insert this command because I'm trying but it doesn't work:

    location / {
    try_files $uri $uri/ /index.php?$args;
    location ~* ^.+.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
    expires max;
    }

    Thanks in advance for the support.

    @sandeep said in CWP - Brotli not work and NGINX not start after upgrade of CWP Pro from v0.9.8.906 to CWP Pro v0.9.8.907 even with the last update to CWP Pro v0.9.8.913.:

    @Automata said in CWP - Brotli not work and NGINX not start after upgrade of CWP Pro from v0.9.8.906 to CWP Pro v0.9.8.907 even with the last update to CWP Pro v0.9.8.913.:

    Hi, you are very very kind, thank you.

    For CWP Pro i use Nginx & Varnish & Apache and not have the .htacces.

    You can tell me precisely where I need to insert this command because I'm trying but it doesn't work:

    location / {
    try_files $uri $uri/ /index.php?$args;
    location ~* ^.+.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
    expires max;
    }

    Thanks in advance for the support.

    you need to add this line only in "location / { " section

    try_files $uri $uri/ /index.php?$args;
    

    ***please note use this only if you're using nginx + php-fpm i.e. nginx as a main server.

    @Automata said in CWP - Brotli not work and NGINX not start after upgrade of CWP Pro from v0.9.8.906 to CWP Pro v0.9.8.907 even with the last update to CWP Pro v0.9.8.913.:

    I have added this line on "Contents of File: /etc/nginx/conf.d/vhosts/My_Website.ssl.conf file here but not work and the website page have this error: ERR_TOO_MANY_REDIRECTS.

    server {
    	listen My_Website:Port;	
    	server_name My-Website  www.My-Website;
    
    	access_log /usr/local/apache/domlogs/My-Website.bytes bytes;
    	access_log /usr/local/apache/domlogs/My-Website.log combined;
    	error_log /usr/local/apache/domlogs/My-Website.error.log error;
    
    location / {
    **try_files $uri $uri/ /index.php?$args;**
    		location ~.*\.(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|html|htm|txt|js|css|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso|woff|ttf|svg|eot|sh)$ {
    			root /home/My_User/public_html;				
    			expires max;
                            try_files $uri @backend;
    		}
    	
    		error_page 405 = @backend;
    		error_page 500 = @custom;
    		add_header X-Cache "HIT from Backend";
    		proxy_pass http://My_Website:Port;
    		include proxy.inc;
    	}
    
    	location @backend {
    		internal;
    		proxy_pass http://My_Website:Port;
    		include proxy.inc;
    	}
    
    	location @custom {
    		internal;
    		proxy_pass http://My_Website:Port;
    		include proxy.inc;
    	}
    
    	location ~ .*\.(php|jsp|cgi|pl|py)?$ {
    		proxy_pass http://My_Website:Port;
    		include proxy.inc;
    	}
    
    	location ~ /\.ht    {deny all;}
    	location ~ /\.svn/  {deny all;}
    	location ~ /\.git/  {deny all;}
    	location ~ /\.hg/   {deny all;}
    	location ~ /\.bzr/  {deny all;}
    
    	disable_symlinks if_not_owner from=/home/My_User/public_html;
    
    	location /.well-known/acme-challenge {
    		default_type "text/plain";
    		alias /usr/local/apache/autossl_tmp/.well-known/acme-challenge;
    	}
    }
    

    Thanks in avance for the support.
    @sandeep said in CWP - Brotli not work and NGINX not start after upgrade of CWP Pro from v0.9.8.906 to CWP Pro v0.9.8.907 even with the last update to CWP Pro v0.9.8.913.:
    Seems you're using apache use this rewrite code in .htaccess : and remove the try_files $uri $uri/ /index.php?$args; from nginx vhost

    # BEGIN WordPress
    
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    
    # END WordPress
    


  • Thanks to your help, now all my websites have started working again.

    But before I rebuild the webserver I assure you that everything worked perfectly without having to have the .htaccess file in the public_html folder of my sites, because the file nginx.conf is already present in this folder.

    Can you help me understand why now I have to use the .htaccess file, is there a way to avoid it by configuring NGINX better?

    Thanks in advance for the support.

    My NGINX.conf file inside the public_html folder of my website:

    # BEGIN W3TC Browser Cache
    brotli on;
    brotli_types text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/richtext text/plain text/xsd text/xsl text/xml image/bmp application/java application/msword application/vnd.ms-fontobject application/x-msdownload image/x-icon application/json application/vnd.ms-access video/webm application/vnd.ms-project application/x-font-otf application/vnd.ms-opentype application/vnd.oasis.opendocument.database application/vnd.oasis.opendocument.chart application/vnd.oasis.opendocument.formula application/vnd.oasis.opendocument.graphics application/vnd.oasis.opendocument.spreadsheet application/vnd.oasis.opendocument.text audio/ogg application/pdf application/vnd.ms-powerpoint image/svg+xml application/x-shockwave-flash image/tiff application/x-font-ttf audio/wav application/vnd.ms-write application/font-woff application/font-woff2 application/vnd.ms-excel;
    gzip on;
    gzip_types text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/richtext text/plain text/xsd text/xsl text/xml image/bmp application/java application/msword application/vnd.ms-fontobject application/x-msdownload image/x-icon application/json application/vnd.ms-access video/webm application/vnd.ms-project application/x-font-otf application/vnd.ms-opentype application/vnd.oasis.opendocument.database application/vnd.oasis.opendocument.chart application/vnd.oasis.opendocument.formula application/vnd.oasis.opendocument.graphics application/vnd.oasis.opendocument.spreadsheet application/vnd.oasis.opendocument.text audio/ogg application/pdf application/vnd.ms-powerpoint image/svg+xml application/x-shockwave-flash image/tiff application/x-font-ttf audio/wav application/vnd.ms-write application/font-woff application/font-woff2 application/vnd.ms-excel;
    location ~ (robots\.txt|sitemap(_index)?\.xml(\.gz)?|[a-z0-9_\-]*sitemap[a-z0-9_\-]*\.(xml|xsl|html)(\.gz)?|([a-z0-9_\-]*?)sitemap([a-z0-9_\-]*)?\.xml) {
        try_files $uri $uri/ $uri.html /index.php?$args;
    }
    location ~ \.(css|htc|less|js|js2|js3|js4)$ {
        expires 31536000s;
        if_modified_since exact;
        add_header Pragma "public";
        add_header Cache-Control "public";
    }
    location ~ \.(html|htm|rtf|rtx|txt|xsd|xsl|xml)$ {
        expires 3600s;
        if_modified_since exact;
        add_header Pragma "public";
        add_header Cache-Control "public";
    }
    location ~ \.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|webp|json|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|webm|mpp|otf|_otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|_ttf|wav|wma|wri|woff|woff2|xla|xls|xlsx|xlt|xlw|zip)$ {
        expires 31536000s;
        if_modified_since exact;
        add_header Pragma "public";
        add_header Cache-Control "public";
    }
    # END W3TC Browser Cache
    
    
    
    
    
    
    # BEGIN W3TC Minify core
    rewrite ^/wp-content/cache/minify/ /index.php last;
    # END W3TC Minify core
    # BEGIN W3TC Page Cache core
    set $w3tc_rewrite 1;
    if ($request_method = POST) {
        set $w3tc_rewrite 0;
    }
    if ($query_string != "") {
        set $w3tc_rewrite 0;
    }
    if ($http_cookie ~* "(comment_author|wp\-postpass|wordpress_logged_in|wptouch_switch_toggle)") {
        set $w3tc_rewrite 0;
    }
    set $w3tc_ua "";
    if ($http_user_agent ~* "(a1-32ab0|a210|a211|b6000-h|b8000-h|bnrv200|bntv400|darwin|gt-n8005|gt-p3105|gt-p6810|gt-p7510|hmj37|hp-tablet|hp\sslate|hp\sslatebook|ht7s3|ideatab_a1107|ideataba2109a|ideos\ss7|imm76d|ipad|k00f|kfjwi|kfot|kftt|kindle|l-06c|lg-f200k|lg-f200l|lg-f200s|m470bsa|m470bse|maxwell|me173x|mediapad|midc497|msi\senjoy\s10\splus|mz601|mz616|nexus|nookcolor|pg09410|pg41200|pmp5570c|pmp5588c|pocketbook|qmv7a|sgp311|sgpt12|shv-e230k|shw-m305w|shw-m380w|sm-p605|smarttab|sonysgp321|sph-p500|surfpad|tab07-200|tab10-201|tab465euk|tab474|tablet|tegranote|tf700t|thinkpad|viewpad|voltaire)") {
        set $w3tc_ua _tablets;
    }
    if ($http_user_agent ~* "((android|bb\d+|meego).+mobile|2.0\ mmp|240x320|\bppc\b|acer\ s100|alcatel|amoi|archos5|asus|au-mic|audiovox|avantgo|bada|benq|bird|blackberry|blazer|cdm|cellphone|cupcake|danger|ddipocket|docomo|docomo\ ht-03a|dopod|dream|elaine/3.0|ericsson|eudoraweb|fly|froyo|googlebot-mobile|haier|hiptop|hp.ipaq|htc|htc\ hero|htc\ magic|htc_dream|htc_magic|huawei|i-mobile|iemobile|iemobile/7|iemobile/7.0|iemobile/9|incognito|iphone|ipod|j-phone|kddi|konka|kwc|kyocera/wx310k|lenovo|lg|lg-gw620|lg/u990|lge\ vx|liquid\ build|maemo|midp|midp-2.0|mmef20|mmp|mobilephone|mot-mb200|mot-mb300|mot-v|motorola|msie\ 10.0|netfront|newgen|newt|nexus\ 7|nexus\ one|nintendo\ ds|nintendo\ wii|nitro|nokia|novarra|openweb|opera.mobi|opera\ mini|opera\ mobi|p160u|palm|panasonic|pantech|pdxgw|pg|philips|phone|playbook|playstation\ portable|portalmmm|proxinet|psp|qtek|s8000|sagem|samsung|samsung-s8000|sanyo|sch|sch-i800|sec|sendo|series60.*webkit|series60/5.0|sgh|sharp|sharp-tq-gx10|small|smartphone|softbank|sonyericsson|sonyericssone10|sonyericssonu20|sonyericssonx10|sph|symbian|symbian\ os|symbianos|t-mobile\ mytouch\ 3g|t-mobile\ opal|tattoo|toshiba|touch|treo|ts21i-10|up.browser|up.link|uts|vertu|vodafone|wap|webmate|webos|willcome|windows.ce|windows\ ce|winwap|xda|xoom|zte)") {
        set $w3tc_ua _phones;
    }
    if ($http_user_agent ~* "(bingbot|googlebot|yandexbot)") {
        set $w3tc_ua _desktop;
    }
    set $w3tc_preview "";
    if ($http_cookie ~* "(w3tc_preview)") {
        set $w3tc_preview _preview;
    }
    set $w3tc_ssl "";
    if ($scheme = https) {
        set $w3tc_ssl _ssl;
    }
    if ($http_x_forwarded_proto = 'https') {
        set $w3tc_ssl _ssl;
    }
    set $w3tc_enc "";
    if ($http_accept_encoding ~ br) {
        set $w3tc_enc _br;
    }
    set $w3tc_enc "";
    if ($http_accept_encoding ~ gzip) {
        set $w3tc_enc _gzip;
    }
    # END W3TC Page Cache core
    
    # START Nginx Rewrites for Rank Math Sitemaps
    rewrite ^/sitemap_index.xml$ /index.php?sitemap=1 last;
    rewrite ^/([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;
    # END Nginx Rewrites for Rank Math Sitemaps
    


  • @Automata said in CWP - NGINX & Varnish & Apache with PHP-FPM server how to configure Pretty Permalink for WordPress:

    wordpress

    nginx.conf will not work in this way nginx will not read it. you need to use .htaccess when using apache as main backend web server


Log in to reply