Search code examples
.htaccessmagentonginxwebserver

Nginx - Magento multiple websites


I have a Magento installation with multiple websites, which is running in Apache web server. Now I want to move these to Nginx web server; how can I achieve this with Nginx configuration? Below is the htaccess code which is redirecting websites:

SetEnvIf HOST 44\.55\.222\.101\:8080 MAGE_RUN_CODE=website_new
SetEnvIf HOST 44\.55\.222\.101\:8080 MAGE_RUN_TYPE=website

Please help.


Solution

  • To run 2 Magento websites on the same server with different ports you bave to use 2 different nginx configuration files for each port under /etc/nginx/conf.d/.

    From the example provided it seems like you are running the websites on ports 80 and 8080. The Magento has provided the default nginx configuration here at http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/configuring_nginx_for_magento

    Use this for port 80 and for 8080 use the below code:

    server {
        listen 8080 default;
        server_name 44.55.222.101; 
        root /var/www/html;
        location / {
            index index.php index.html index.htm;
            try_files $uri $uri/ @handler;
            expires 30d;
        }
        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/ {
            auth_basic           "Restricted";
            auth_basic_user_file htpasswd;
            autoindex            on;
        }
        location  /. {
            return 404;
        }
        location @handler {
            rewrite / /index.php;
        }
        location ~ .php/ {
            rewrite ^(.*.php)/ $1 last;
        }
        location ~ .php$ {
            if (!-e $request_filename) { rewrite / /index.php last; } 
            expires        off;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_param  HTTPS $fastcgi_https;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  MAGE_RUN_CODE website_new; 
            fastcgi_param  MAGE_RUN_TYPE website;
            include        fastcgi_params; 
        }
    }