Last active
August 29, 2015 14:16
-
-
Save ottonet/006a6870a3940c790e92 to your computer and use it in GitHub Desktop.
auto-resolving nginx magento development config with multi-domain and multi-storeview support.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 80 default_server; | |
listen [::]:80 default_server ipv6only=on; | |
# Automatic generation of the server-name. | |
# both subdomain.domain.tld and storeview.subdomain.domain.tld work. | |
server_name ~^(((?<storeview>.*)\.)?((?<subdomain>.*)\.)(?<domain>[^.]+)\.(?<tld>[^.]+))$; | |
# set root folder. both storeview.dev.magen.to and dev.magen.to resolve to /var/www/magen/htdocs | |
root /var/www/${subdomain}/htdocs; | |
# set magento runcode. for example: mysite_nl.dev.magen.to resolves to mysite_nl, dev.magen.to results in default. | |
set $runcode "${storeview}"; | |
# sets the domainname for rewrites | |
set $s1 $1; | |
# optional: modified access_log | |
access_log /var/log/nginx/dev.log dev; | |
client_max_body_size 20M; | |
rewrite_log on; | |
location / { | |
index index.php; | |
try_files $uri $uri/ @handler; | |
expires 180d; ## Assume all files are cachable | |
} | |
## Emulate robots.txt for all dev sites | |
location /robots.txt { | |
return 200 "User-agent: *\nDisallow: /"; | |
} | |
## These locations would be hidden by .htaccess normally | |
location ^~ /app/ { deny all; } | |
location ^~ /includes/ { deny all; } | |
location ^~ /lib/ { deny all; } | |
location ^~ /media/downloadable/ { deny all; } | |
location ^~ /pkginfo/ { deny all; } | |
location ^~ /report/config.xml { deny all; } | |
location ^~ /var/ { deny all; } | |
location /var/export/ { ## Allow admins only to view export folder | |
auth_basic "Restricted"; ## Message in login window | |
auth_basic_user_file /var/www/.htpasswd; | |
autoindex on; | |
} | |
## Disable .htaccess and other hidden files | |
location ~ /\. { | |
return 404; | |
} | |
location @handler { ## Magento front handler | |
rewrite / /index.php; | |
} | |
location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler | |
rewrite ^(.*.php)/ $1 last; | |
} | |
location ~ \.php(/.*)? { ## Execute PHP Scripts | |
if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files misses | |
expires off; ## Do not cache dynamic content | |
set $runtype store; | |
fastcgi_pass unix:/var/run/php5-fpm.sock; | |
fastcgi_split_path_info ^(.*\.php)(/.*)?$; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
fastcgi_param MAGE_RUN_CODE $runcode; | |
fastcgi_param MAGE_RUN_TYPE $runtype; | |
fastcgi_read_timeout 1800; | |
include fastcgi_params; ## See /etc/nginx/fastcgi_params | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
create a wildcard DNS entry like:
and point this to your development server at 127.0.0.1 or a "public" dev server, for instance at Digital Ocean.
examples:
site1.mydevelopmendomain.tld resolves to /var/www/site1
site2.mydevelopmentdomain.tld resolves to /var/www/site2
storeview_nl.site2.mydevelopmentdomain.tld resolves to /var/www/site2 and sets $runcode to storeview_nl
storeview_en.dev.otherdomain.tld resolves to /var/www/dev/ and sets $rundcode to storeview_en
Update 02/03/2015
Added automatic robots.txt emulation for all sites.