Implementing Vary:User-Agent

MageStack natively supports the Vary: User-Agent header, however, as it isn't a setting applicable to all stores, it is disabled by default. To enable the User-Agent vary header, you only need to set a single variable in your vhosts configuration, Edit your ___general/example.com.conf (where example.com is your chosen domain), and add set $magestack_vary_user_agent true; Then … Continue reading

Rate Limiting Requests

Table of ContentsOptions Enabling Custom Rate Limiter Examples Rate limit AJAX search to 1 request per 10 seconds Rate limit AJAX search to 1 request per 10 seconds, but whitelist given IPs Rate limit AJAX search to 1 request per 10 seconds, but only for specific country codes and whitelist given IPs Rate limit account … Continue reading

Altering Static File Handling

Table of ContentsExamplesMageStack treats dynamic content different to static content, Eg. Different HTTP timeouts Different caching rules Different DOS rules etc. Static files by default are defined here To override the default behavior of a 404 error on non-existent static content (eg. for Magento downloadable content), you can either add a location directive, or add … Continue reading

Rate Limiting API Requests

Table of ContentsOptions Enabling API Rate Limiter Examples Rate limit API to 1 request per 10 seconds Conditionally Rate limit by IP to 1 request per 10 seconds Conditionally Rate limit by user agent to 1 request per 10 secondsThe Magento API is most commonly used when a store is integrated with a 3rd party … Continue reading

Implementing If-Modified-Since

Table of ContentsAdvanced Configuration Easy Configuration NotesFor static content, the expires headers are set by default in MageStack. They can be overridden using either the native Nginx expires directive, or the more powerful $magestack_cache_lifetime (see Controlling Varnish cacheable content. For dynamic content, this is not so consistent, as Nginx will not set any expires directives, … Continue reading

Redirect all content from HTTP to HTTPS

If you want to ensure that every page on your site is served over HTTPS, you should add the following rewrite rules, replace www.example.com with your SSL enabled domain In ___general/example.com.conf, # Redirect all content to HTTPS set $redirect "0"; if ($host ~* "^(www\.)?example.com$") { set $redirect "go"; } if ($my_http = http) { set … Continue reading

Pre-Defined Server Variables

Table of ContentsVariables User Home Script_Filename Mage_Run_Code Mage_Run_Type Query_String Request_Method Content_Type Content_Length Script_Name Request_Uri Document_Uri Document_Root Server_Protocol Gateway_Interface Server_Software Remote_Port Server_Addr Server_Port Server_Name Redirect_Status Remote_Addr Https Http_X_Forwarded_Protocol Geoip_Country_Code Geoip_City_Country_Code3 Geoip_Country_Name Geoip_Region Geoip_City Geoip_Postal_Code Geoip_City_Continent_Code Geoip_Latitude Geoip_Longitude Http_Host Http_User_Agent Http_Accept Http_Accept_Language Http_Cookie Http_Magestack_Loadbalancer Http_Magestack_Dos_Stats Http_Magestack_Area Http_Magestack_Tag Http_Magestack_Whitelisted_Http_host Http_Magestack_Whitelisted_Ip Http_Magestack_Whitelisted_Uri Http_MageStack_Whitelisted_Useragent Http_X_Forwarded_For Http_Varnish_Enabled Http_Separate_Scheme Http_Accept_Encoding Http_Connection Php_Self … Continue reading

Adding rewrite for www to non-www

The easiest way to add an Nginx rewrite to redirect your traffic from www to non-www is to add the following Nginx code snippet to your domain's ___general/example.com.conf file. set $redirect "0"; if ($host ~* "^www\.example\.com$") { set $redirect "go"; } if ($redirect = "go") { rewrite ^(.*)$ $my_http://example.com$1 permanent; } ! Be sure to … Continue reading

Multistore Magento Configuration

Table of ContentsSharing the document root Identical document root Different document root Setting the run codes Example: Set environment variables for a domain Example: Set environment variables for a sub-domain Example: Set environment variables for a sub-directoryThere are two elements to making a multi-store environment, Ensure all stores access a common document root (ie. the … Continue reading

Nginx Configuration Files

Table of ContentsScope Configuration files Applying changesOn MageStack, Nginx has 4 separate configuration files per vhost defined under 2 different directories/scopes, ___general and ___rewrites. Scope Each configuration file serves its own purpose - knowing which to use first is answered by the scope you need to edit. On MageStack, Nginx has two scopes, server and … Continue reading