Skip to content

Instantly share code, notes, and snippets.

@eneiasramos
Forked from hanhpv/magento-1-nginx.md
Created April 24, 2023 06:47
Show Gist options
  • Save eneiasramos/3550d903687dcbf85fa7d2067dc52675 to your computer and use it in GitHub Desktop.
Save eneiasramos/3550d903687dcbf85fa7d2067dc52675 to your computer and use it in GitHub Desktop.
Magento 1 nginx configuration
server { 
	listen 80; 
	root /Users/admin/htdocs/vax-uk;
	index index.php index.html index.htm;
	 
	server_name vax.local; 
	access_log /usr/local/etc/nginx/logs/vax_access.log;
	access_log /usr/local/etc/nginx/logs/vax_error.log;
	 
	## 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/            { deny all; } 
	 
	# deny htaccess files 
	location ~ /\. { 
		deny  all; 
		access_log off; 
		log_not_found off; 
	} 
	 
	location ~*  \.(jpg|jpeg|png|gif|ico)$ { 
		expires 365d; 
		log_not_found off; 
		access_log off; 
	} 
	 
	location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler 
		rewrite ^(.*.php)/ $1 last; 
	}

	## rewrite anything else to index.php
	location / { 
		index index.html index.php;
		try_files $uri $uri/ /index.php?$query_string;
		expires 30d;
		rewrite /api/rest /api.php?type=rest;
	}
	 
	# pass the PHP scripts to FPM socket 
	location ~ \.php$ { 
		fastcgi_pass 127.0.0.1:9000;
		fastcgi_param MAGE_RUN_TYPE store;
		fastcgi_param  MAGE_RUN_CODE $MAGE_RUN_CODE;
		fastcgi_index index.php; 
		include fastcgi.conf; 
	}
}

map $http_host $MAGE_RUN_CODE {
    vax.local uk_default;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment