Join the community today
Become a Member

Nginx converting htaccess to nginx

Discussion in 'Install & Upgrades or Pre-Install Questions' started by Altair, Oct 5, 2020.

  1. Altair

    Altair Member

    68
    3
    8
    Jan 27, 2018
    Ratings:
    +3
    Local Time:
    1:21 PM
    Hi @eva2000,

    I hope you can help me converting this htaccess to nginx to put it into vhost?
    because this htaccess is mandatory to an addon/theme I'm using on Wordpress,
    and speeds things up by a big difference.

    Code:
    # BEGIN GZIP COMPRESSION
    # The directives (lines) between "BEGIN GZIP COMPRESSION" and "END GZIP COMPRESSION" are
    # dynamically generated, and should only be modified via WordPress filters.
    # Any changes to the directives between these markers will be overwritten.
    <IfModule mod_gzip.c>
    mod_gzip_on Yes
    mod_gzip_dechunk Yes
    mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
    mod_gzip_item_include handler ^cgi-script$
    mod_gzip_item_include mime ^text/.*
    mod_gzip_item_include mime ^application/x-javascript.*
    mod_gzip_item_exclude mime ^image/.*
    mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
    </IfModule>
    # END GZIP COMPRESSION
    # BEGIN DEFLATE COMPRESSION
    # The directives (lines) between "BEGIN DEFLATE COMPRESSION" and "END DEFLATE COMPRESSION" are
    # dynamically generated, and should only be modified via WordPress filters.
    # Any changes to the directives between these markers will be overwritten.
    <IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE "application/atom+xml" \
    "application/javascript" \
    "application/json" \
    "application/ld+json" \
    "application/manifest+json" \
    "application/rdf+xml" \
    "application/rss+xml" \
    "application/schema+json" \
    "application/vnd.geo+json" \
    "application/vnd.ms-fontobject" \
    "application/x-font" \
    "application/x-font-opentype" \
    "application/x-font-otf" \
    "application/x-font-truetype" \
    "application/x-font-ttf" \
    "application/x-javascript" \
    "application/x-web-app-manifest+json" \
    "application/xhtml+xml" \
    "application/xml" \
    "font/eot" \
    "font/otf" \
    "font/ttf" \
    "font/opentype" \
    "image/bmp" \
    "image/svg+xml" \
    "image/vnd.microsoft.icon" \
    "image/x-icon" \
    "text/cache-manifest" \
    "text/css" \
    "text/html" \
    "text/javascript" \
    "text/plain" \
    "text/vcard" \
    "text/vnd.rim.location.xloc" \
    "text/vtt" \
    "text/x-component" \
    "text/x-cross-domain-policy" \
    "text/xml"
    </IfModule>
    # END DEFLATE COMPRESSION
    # BEGIN KEEP ALIVE
    # The directives (lines) between "BEGIN KEEP ALIVE" and "END KEEP ALIVE" are
    # dynamically generated, and should only be modified via WordPress filters.
    # Any changes to the directives between these markers will be overwritten.
    <ifModule mod_headers.c>
    Header set Connection keep-alive
    </ifModule>
    # END KEEP ALIVE
    # BEGIN EXPIRES CACHING
    # The directives (lines) between "BEGIN EXPIRES CACHING" and "END EXPIRES CACHING" are
    # dynamically generated, and should only be modified via WordPress filters.
    # Any changes to the directives between these markers will be overwritten.
    <IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/css "access 1 month"
    ExpiresByType text/html "access 1 month"
    ExpiresByType image/gif "access 1 year"
    ExpiresByType image/png "access 1 year"
    ExpiresByType image/jpg "access 1 year"
    ExpiresByType image/jpeg "access 1 year"
    ExpiresByType image/x-icon "access 1 year"
    ExpiresByType image/svg+xml "access plus 1 month"
    ExpiresByType audio/ogg "access plus 1 year"
    ExpiresByType video/mp4 "access plus 1 year"
    ExpiresByType video/ogg "access plus 1 year"
    ExpiresByType video/webm "access plus 1 year"
    ExpiresByType application/atom+xml "access plus 1 hour"
    ExpiresByType application/rss+xml "access plus 1 hour"
    ExpiresByType application/pdf "access 1 month"
    ExpiresByType application/javascript "access 1 month"
    ExpiresByType text/x-javascript "access 1 month"
    ExpiresByType text/x-component "access plus 1 month"
    ExpiresByType application/x-shockwave-flash "access 1 month"
    ExpiresByType font/opentype "access plus 1 month"
    ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
    ExpiresByType application/x-font-ttf "access plus 1 month"
    ExpiresByType application/font-woff "access plus 1 month"
    ExpiresByType application/font-woff2 "access plus 1 month"
    ExpiresDefault "access 1 month"
    </IfModule>
    # END EXPIRES CACHING
    # BEGIN CACHE-CONTROL HEADERS
    # The directives (lines) between "BEGIN CACHE-CONTROL HEADERS" and "END CACHE-CONTROL HEADERS" are
    # dynamically generated, and should only be modified via WordPress filters.
    # Any changes to the directives between these markers will be overwritten.
    <ifModule mod_headers.c>
    <filesMatch "\.(ico|jpe?g|png|gif|swf)$">
    Header set Cache-Control "public"
    </filesMatch>
    <filesMatch "\.(css)$">
    Header set Cache-Control "public"
    </filesMatch>
    <filesMatch "\.(js)$">
    Header set Cache-Control "private"
    </filesMatch>
    <filesMatch "\.(x?html?|php)$">
    Header set Cache-Control "private, must-revalidate"
    </filesMatch>
    </ifModule>
    # END CACHE-CONTROL HEADERS
    # BEGIN MOD PAGESPEED
    # The directives (lines) between "BEGIN MOD PAGESPEED" and "END MOD PAGESPEED" are
    # dynamically generated, and should only be modified via WordPress filters.
    # Any changes to the directives between these markers will be overwritten.
    <IfModule pagespeed_module>
    ModPagespeed on
    ModPagespeedEnableFilters rewrite_css,combine_css
    ModPagespeedEnableFilters recompress_images
    ModPagespeedEnableFilters convert_png_to_jpeg,convert_jpeg_to_webp
    ModPagespeedEnableFilters collapse_whitespace,remove_comments
    </IfModule>
    # END MOD PAGESPEED
    # BEGIN LITESPEED CACHE
    # The directives (lines) between "BEGIN LITESPEED CACHE" and "END LITESPEED CACHE" are
    # dynamically generated, and should only be modified via WordPress filters.
    # Any changes to the directives between these markers will be overwritten.
    <IfModule LiteSpeed>
    CacheEnable public
    RewriteEngine On
    RewriteCond %{REQUEST_METHOD} ^GET|HEAD$
    RewriteCond %{HTTP_HOST} ^sample.com|sample.net|sample.org [NC]
    RewriteCond %{REQUEST_URI} !login|admin|register|post|cron
    RewriteCond %{QUERY_STRING} !nocache
    RewriteRule .* - [E=Cache-Control:max-age=300]
    </IfModule>
    # END LITESPEED CACHE
    # BEGIN SEREVER SIGNATURE
    # The directives (lines) between "BEGIN SEREVER SIGNATURE" and "END SEREVER SIGNATURE" are
    # dynamically generated, and should only be modified via WordPress filters.
    # Any changes to the directives between these markers will be overwritten.
    ServerSignature Off
    # END SEREVER SIGNATURE
     
  2. eva2000

    eva2000 Administrator Staff Member

    45,441
    10,312
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,994
    Local Time:
    9:21 PM
    Nginx 1.19.x
    MariaDB 5.5/10.x
    As per convert apache rewrites to nginx rewrites, all the above is for setting browser cache control/expires headers and gzip compress of static files which you do not need with Centmin Mod Nginx as out of the box nginx vhosts created all have expire headers/cache control set for static files in global server wide include file at /usr/local/nginx/conf/staticfiles.conf as per Centmin Mod Configuration Files - CentminMod.com LEMP Nginx web stack for CentOS
    and gzip compression server wide in /usr/local/nginx/conf/nginx.conf
    Code (Text):
            gzip on;
            gzip_vary   on;
            gzip_disable "MSIE [1-6]\.";
            gzip_static on;
            gzip_min_length   1400;
            gzip_buffers      1024 8k;
            gzip_http_version 1.0;
            gzip_comp_level 5;
            gzip_proxied    any;
            gzip_types text/plain text/css text/xml application/javascript application/x-javascript application/xml application/xml+rss application/ecmascript application/json image/svg+xml;