• Home
    • English
    • 中文
  • About Us
  • Services
    • SEO Services
    • Website Design Service
  • Projects
  • Docs
  • Blog
    • Affiliate
    • Ecommerce
    • Frontend
    • linux
      • nginx
    • PHP
      • Magento
      • wordpress
    • Python
    • SEO
    • Web
  • Contact Us

Subscribe to Updates

Get the latest creative news from FooBar about art, design and business.

What's Hot

Design a plugin for wordpress woocommerce to display a tab to show attachment download

2024-04-06

TranslatePress v2.6.9 – WordPress Translation Plugin

2023-12-25

A Linux batch script converting pictures to webp format

2023-07-10
Facebook Twitter Instagram
  • 中文
  • English
Facebook Twitter Instagram Pinterest VKontakte
Weilai Tech Weilai Tech
  • Home
    • English
    • 中文
  • About Us
  • Services
    • SEO Services
    • Website Design Service
  • Projects
  • Docs
  • Blog
    • Affiliate
    • Ecommerce
    • Frontend
    • linux
      • nginx
    • PHP
      • Magento
      • wordpress
    • Python
    • SEO
    • Web
  • Contact Us
Weilai Tech Weilai Tech
Home»linux»Tutorial—Set up multiple websites or stores with nginx
linux

Tutorial—Set up multiple websites or stores with nginx

OxfordBy Oxford2018-07-05Updated:2019-01-15No Comments4 Mins Read
Facebook Twitter Pinterest LinkedIn Tumblr Email
Share
Facebook Twitter LinkedIn Pinterest Email

Tutorial—Set up multiple websites or stores with nginx

Set up multiple websites with nginx

 

https://devdocs.magento.com/guides/v2.0/config-guide/multi-site/ms_nginx.html

 

This tutorial shows you step-by-step how to set up multiple websites using nginx .

Assumptions

We assume the following:

  • You’re working on a development machine (laptop, virtual machine, and so on)Additional tasks might be required to deploy multiple websites in a hosted environment; check with your hosting provider for more information.

    Additional tasks are required to set up Magento Commerce (Cloud). After you complete the tasks discussed in this topic, see Set up multiple Magento Commerce (Cloud) websites or stores.

  • You use one virtual host per website; the virtual host configuration files are located in /etc/nginx/sites-available
  • You use nginx.conf.sample provided by Magento with only the modifications discussed in this tutorial, and two line configurations.
  • The Magento software is installed in /var/www/html/magento2
  • You have two websites other than the default:
    • french.mysite.mg with website code french and store view code fr
    • german.mysite.mg with website code german and store view code de

    Refer to Create websites and Create store views for help locating these values.

Roadmap for setting up multiple websites with nginx

Setting up multiple stores consists of the following tasks:

  1. Set up websites, stores, and store views in the Magento Admin .
  2. Create one nginx virtual host per Magento website .
  3. Pass the values of the Magento variables $MAGE_RUN_TYPE and $MAGE_RUN_CODE to nginx using the Magento-provided nginx.conf.sample.
    • $MAGE_RUN_TYPE can be either store or website
      • Use website to load your website in your storefront.
      • Use store to load any store view in your storefront.
    • $MAGE_RUN_CODE is the unique website or store view code that corresponds to $MAGE_RUN_TYPE

Step 2: Create nginx virtual hosts

This section discusses how to load websites on the storefront . You can use either websites or store views; if you use store views, you must adjust parameter values accordingly. You must complete the tasks in this section as a user with root privileges.

To create virtual hosts:

  1. Open a text editor and add the following contents to a new file named /etc/nginx/sites-available/french.mysite.mg.conf:
    map $http_host $MAGE_RUN_CODE {
       french.mysite.mg french;
    }
    map $http_host $MAGE_RUN_TYPE {
        french.mysite.mg store
    }
    
    server {
       listen 80;
       server_name french.mysite.mg;
       set $MAGE_ROOT /var/www/html/magento2;
       set $MAGE_MODE developer;
       include /var/www/html/magento2/nginx.conf;
    }
    

Create another file named german.mysite.mg.conf in the same directory with the following contents:

map $http_host $MAGE_RUN_CODE {
   german.mysite.mg german;
}
map $http_host $MAGE_RUN_TYPE {
    german.mysite.mg store
}

server {
   listen 80;
   server_name german.mysite.mg;
   set $MAGE_ROOT /var/www/html/magento2;
   set $MAGE_MODE developer;
   include /var/www/html/magento2/nginx.conf;
}

 

  • Save your changes to the files and exit the text editor.
  • Change nginx.conf.sample content
    location ~ (index|get|static|report|404|503|health_check).php$ {
        try_files $uri =404;
        fastcgi_pass   fastcgi_backend;
        fastcgi_buffers 1024 4k;
    
        fastcgi_param  PHP_FLAG  "session.auto_start=off n suhosin.session.cryptua=off";
        fastcgi_param  PHP_VALUE "memory_limit=756M n max_execution_time=18000";
        fastcgi_read_timeout 600s;
        fastcgi_connect_timeout 600s;
    
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
    

 

to

location ~ (index|get|static|report|404|503|health_check).php$ {
    try_files $uri =404;
    fastcgi_pass   fastcgi_backend;
    fastcgi_buffers 1024 4k;

    fastcgi_param  PHP_FLAG  "session.auto_start=off n suhosin.session.cryptua=off";
    fastcgi_param  PHP_VALUE "memory_limit=756M n max_execution_time=18000";
    fastcgi_param  MAGE_RUN_TYPE $MAGE_RUN_TYPE;
	    fastcgi_param  MAGE_RUN_CODE $MAGE_RUN_CODE;
    fastcgi_read_timeout 600s;
    fastcgi_connect_timeout 600s;

    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

Verify the server configuration:

nginx -t

If successful, the following message displays:

nginx: configuration file /etc/nginx/nginx.conf test is successful

 

  • If errors display, check the syntax of your virtual host configuration files.
  • Create symbolic links in the /etc/nginx/sites-enabled directory:
    cd /etc/nginx/sites-enabled
    ln -s /etc/nginx/sites-available/french.mysite.mg french.mysite.mg
    ln -s /etc/nginx/sites-available/german.mysite.mg german.mysite.mg
    

 

For more detail about the map directive, see nginx documentation on the map directive.

Verify your site

Unless you have DNS set up for your stores’ URLs, you must add a static route to the host in your hosts file:

  1. Locate your operating system’s hosts file.
  2. Add the static route in the format:
    <ip address> french.mysite.mg
    <ip address> german.mysite.mg
    

Go to one of the following URLs in your browser:

http://mysite.mg/admin
http://french.mysite.mg/frenchstoreview
http://german.mysite.mg/germanstoreview

You’re done!

  • Additional tasks might be required to deploy multiple websites in a hosted environment; check with your hosting provider for more information.
  • Additional tasks are required to set up Magento Commerce (Cloud); for more information, see Set up multiple Cloud websites or stores

Troubleshooting

  • If your French and German sites return 404s but your Admin loads, make sure you completed Step 6: Add the store code to the base URL.
  • If all URLs return 404s, make sure you restarted your web server.
  • If the Magento Admin doesn’t function properly, make sure you set up your virtual hosts properly.
Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
Avatar photo
Oxford

Related Posts

A Linux batch script converting pictures to webp format

2023-07-10

how to install magento 2.3.1 on cyberpanel enterprise

2021-09-29

How to Install Windows Nano Server on ESXi

2021-06-22

How To Install vSphere ESXi 7.0 on Bare-metal Servers

2021-06-18
Recent Posts
  • Design a plugin for wordpress woocommerce to display a tab to show attachment download
  • TranslatePress v2.6.9 – WordPress Translation Plugin
  • A Linux batch script converting pictures to webp format
  • Hearing aid listed company official website SEO case
  • how to use docker to run php5.6 plus apache
July 2018
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
3031  
« May   Sep »
Tags
app branding design digital Docly docs etc faq fix github Helpdesk Image issue magento Manual marketing memecached Photography planing seo sequrity tips Travel ui/ux web WordPress 爬虫
Editors Picks
About Us

Guangzhou Weilai Technology is a foreign trade integrated marketing service provider focusing on Google as the drainage center and marketing self-built website as the carrier.

Email Us: [email protected]
Contact: +86 18676917505

Facebook Pinterest YouTube LinkedIn
Recent Posts
  • Design a plugin for wordpress woocommerce to display a tab to show attachment download
  • TranslatePress v2.6.9 – WordPress Translation Plugin
  • A Linux batch script converting pictures to webp format
  • Hearing aid listed company official website SEO case
  • how to use docker to run php5.6 plus apache
From Flickr
Website Design Case
© 2024 Copyright by Guangzhou Weilai Technology Co.,Ltd..
  • Home
  • About Us
  • SEO Services
  • Website Design Service
  • Projects
  • Blog
  • Contact Us

Type above and press Enter to search. Press Esc to cancel.