Windows Nginx Virtual Host Multi-site configuration detailed

Source: Internet
Author: User
Tags mysql tutorial phpinfo

Windows Nginx Virtual Host Multi-site configuration detailed 

  This tutorial is intended for classmates who have already configured the NGINX+PHP+MYSQL environment for Windows systems.

If you have not yet set up a WNMP environment, see the Windows7 configuration Nginx+php+mysql Tutorial.

First explain the purpose of configuring multi-site: In the production environment, if the system all the code files are placed in the public directory, it is easy to see the system source, this is very insecure, so it is necessary to expose only the index.php of the portal file directory. In the same server, multiple systems may be running, so you must expose multiple portal file directories to access different systems with different domain names. So this requires the use of virtual host for multiple sites.

Go directly to the following topics:

I. Configuring VIRTUALHOST Multi-site

 Take www.lee.com and www.lee1.com for two chestnuts.

 1. Define the site domain name.

first modify the system Hosts file (the Hosts file is located in the C:\Windows\System32\drivers\etc folder). Before you modify the Hosts file to determine the permissions to modify this file, right mouse button Hosts file, click Properties, as shown in click Edit to modify the user's permissions can be written.

        

   Then, at the bottom of the Hosts file, add as follows: (optionally add as required)

127.0.0.1 www.lee.com

127.0.0.1 www.lee1.com

 2. Create a site public file directory and create a test file

  I set the file directory:

      

    Nginx folder for Nginx-related content, PHP-related content.

Where Lee and Lee1 are exposed by the two files directory, the file directory path and folder name can be changed according to the site domain name.

Add two PHP files to the Lee and Lee1 folders for testing.

Add index.php to the Lee folder and edit the content to:

<? PHP                 Echo "Www.lee.com<br/>";             Echo Phpinfo ();        ? >            

add index.php to the Lee1 folder and edit the contents as:

<? PHP                 Echo "Www.lee1.com<br/>";             Echo Phpinfo ();        ? >            

 3. Modify the nginx.conf configuration file

  Modify the following code location in the configuration file: (nginx.conf configuration is located in the nginx/conf/folder)

# Another virtual host using mix of ip-, name-, and port-based configuration                            #                            #server {                            #    Listen       8000;                            #    Listen       somename:8080;                            #    server_name  somename  alias  another.alias;                                                    # location    /{                            #        root   html;                            #        Index  index.html index.htm;                            #    }                            #}                        

Modify the above configuration code to:

# Another virtual host using mix of ip-, name-,and port-based configuration # #modify by Lee20160902For virtual host Www.lee.com-s server {Listen 80;Access_log Logs/lee.access.log;Error_log Logs/lee.error.log;server_name www.lee.com;                    Location /{root C:/wnmp/lee;Index index.html index.htm index.php;                        } location ~ \.php$ {root c:/wnmp/lee
    ;Fastcgi_pass 127.0.0.1:9001;Fastcgi_index index.php;Fastcgi_param script_filename $document _root$fastcgi_script_name;Include Fastcgi_params;                        }} #modify by Lee20160902For virtual host www.lee.com-e #modify by Lee20160902For virtual host Www.lee1.com-s server {Listen 
    80;Access_log Logs/lee1.access.log;Error_log Logs/lee1.error.log;server_name www.lee1.com;                    Location /{root c:/wnmp/lee1;Index index.html index.htm index.php;                        } location ~ \.php$ {root c:/wnmp/ Lee1;Fastcgi_pass 127.0.0.1:9001;Fastcgi_index index.php;Fastcgi_param script_filename $document _root$fastcgi_script_name;Include Fastcgi_params;                        }} #modify by Lee20160902 for Virtual host WWW.LEE1.COM-E

where server_name is the site domain name set in the Hosts file, Access_log and error_log are the log files, and the file name responds to changes.

Root exposes the file directory to the site that you set up for step 2.

 4. Testing

  Restart Nginx and php-cgi services, starting method see my previous article------windows7 Configuration Nginx+php+mysql Tutorial (step 4 (5))

Open Browser, Access www.lee.com

     

   Visit www.lee1.com

      

    VirtualHost Multi-site configuration is successful!

The next article will be: Windows Nginx configuration OpenSSL for HTTPS access (including certificate generation)

   Reference: http://www.jb51.net/article/27533.htm

Windows Nginx Virtual Host Multi-site configuration detailed

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.