Advertisement
Guest User

Nginx Magento Single-domain Multistore Config

a guest
Mar 27th, 2015
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. server {
  2.     listen 444 ssl spdy;            ## SPDY is On! SPDY could be activated only when SSL options is on either
  3.  
  4.     root /var/www/example.com/htdocs/;  ## Don't forget to specify a correct path
  5.     index index.html index.php;
  6.  
  7.     server_name example.com;        ## Don't forget to specify a correct domain name  
  8.  
  9.     ssl on;                 ## Turning SSL on. Certificate are mandatory. Use http://startssl.com to obtain free one.
  10.     ssl_certificate /etc/apache2/ssl/example.com.crt;
  11.     ssl_certificate_key /etc/apache2/ssl/example.comkey;
  12.  
  13.     proxy_send_timeout 600;
  14.     proxy_read_timeout 600;
  15.  
  16.     error_log  /var/www/example.com/logs/nginx-error.log;
  17.     access_log /var/www/example.com/logs/nginx-access.log;
  18.  
  19.     location /us/ {
  20.         set $mage_run_code 'store_usa'; ## Important! Here you MUST to set your webstore-specific store code! (System->Manage Stores in Magento)
  21.         index index.html index.php;     ## Allow a static html file to be shown first
  22.             try_files $uri $uri/ @store_us; ## If missing pass the URI to Magento's front handler
  23.             expires 30d;                    ## Assume all files are cacheable
  24.     }
  25.  
  26.     location /ca/ {
  27.         set $mage_run_code "store_ca";  ## Important! Here you MUST to set your webstore-specific store code! (System->Manage Stores in Magento)
  28.         index index.html index.php;     ## Allow a static html file to be shown first
  29.             try_files $uri $uri/ @store_ca; ## If missing pass the URI to Magento's front handler
  30.             expires 30d;                    ## Assume all files are cacheable
  31.     }
  32.  
  33.     location / {                ## This location block makes working your start page http://example.com/ (i. e. without /us or /ca)
  34.             index index.html index.php;     ## Allow a static html file to be shown first
  35.             try_files $uri $uri/ @default;  ## If missing pass the URI to Magento's front handler
  36.             expires 30d;            ## Assume all files are cacheable
  37.     }
  38.  
  39.     ## These locations should be hidden
  40.         location ^~ /app/                { deny all; }
  41.         location ^~ /includes/           { deny all; }
  42.         location ^~ /lib/                { deny all; }
  43.         location ^~ /media/downloadable/ { deny all; }
  44.         location ^~ /pkginfo/            { deny all; }
  45.         location ^~ /report/config.xml   { deny all; }
  46.         location ^~ /var/                { deny all; }
  47.  
  48.     location /var/export/ {             ## Allow admins only to view export folder
  49.             auth_basic           "Restricted";  ## Message shown in login window
  50.             auth_basic_user_file htpasswd;      ## See /etc/nginx/htpassword
  51.             autoindex            on;
  52.     }
  53.  
  54.     location  /. {                  ## Disable .htaccess and other hidden files
  55.         return 404;
  56.     }
  57.  
  58.     location @default {                 ## Handler for http://example.com/
  59.         rewrite / /index.php;
  60.     }
  61.  
  62.     location @store_us {                ## Handler for http://example.com/us/
  63.         rewrite / /us/index.php;
  64.     }
  65.  
  66.     location @store_ca {                ## Handler for http://example.com/ca/
  67.         rewrite / /ca/index.php;
  68.     }
  69.  
  70.     location ~ .php/ {              ## Forward paths like /js/index.php/x.js to relevant handler
  71.         rewrite ^(.*.php)/ $1 last;
  72.     }
  73.  
  74.     location ~ /us/index.php {
  75.         if (!-e $request_filename) { rewrite / /us/index.php last; }    ## Catch 404s that try_files miss
  76.  
  77.             expires        off;                                             ## Do not cache dynamic content
  78.             fastcgi_pass unix:/var/run/php5-fpm.sock;
  79.             fastcgi_param  HTTPS $fastcgi_https;
  80.             fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
  81.             fastcgi_param  MAGE_RUN_CODE $mage_run_code;
  82.             fastcgi_param  MAGE_RUN_TYPE website;
  83.             include        fastcgi_params;                  ## See /etc/nginx/fastcgi_params
  84.     }
  85.  
  86.     location ~ /ca/index.php {
  87.         if (!-e $request_filename) { rewrite / /ca/index.php last; }        ## Catch 404s that try_files miss
  88.  
  89.         expires        off;                                             ## Do not cache dynamic content
  90.             fastcgi_pass unix:/var/run/php5-fpm.sock;
  91.             fastcgi_param  HTTPS $fastcgi_https;
  92.             fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
  93.             fastcgi_param  MAGE_RUN_CODE $mage_run_code;
  94.             fastcgi_param  MAGE_RUN_TYPE website;
  95.             include        fastcgi_params; ## See /etc/nginx/fastcgi_params
  96.  
  97.         }
  98.  
  99.         location ~ .php$ { ## Execute PHP scripts
  100.         if (!-e $request_filename) { rewrite / /index.php last; }   ## Catch 404s that try_files miss
  101.        
  102.         expires        off;                         ## Do not cache dynamic content
  103.         fastcgi_pass unix:/var/run/php5-fpm.sock;
  104.             fastcgi_param  HTTPS $fastcgi_https;
  105.         fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
  106.             include        fastcgi_params;                  ## See /etc/nginx/fastcgi_params
  107.     }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement