1, source code to install Nginx, and configure Port-based virtual host
Configuration requirements: The host IP address is 172.16.249.96, which requires a virtual host of 80 ports and 8080 ports respectively.
In the first chapter has explained how to compile the installation Nginx, all here will no longer demonstrate the installation process, directly based on the installed base, configure the Port-based virtual host.
Step one: The installation of Nginx.vim makes it possible to use VIM to edit the nginx configuration file with syntax highlighting (this is not required, just to facilitate editing of the configuration file).
(1) Download nginx.vim (download page: http://www.vim.org/scripts/script.php?script_id=1886)
(2) Place the Nginx.vim in the ~/.vim/syntax/directory
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/57/99/wKioL1SgDA-DMHaSAAC0rDDIO0E118.jpg "title=" 17.png "alt=" Wkiol1sgda-dmhasaac0rddio0e118.jpg "/>
(3) Configure Nginx.vim: Add the following line in the ~/.vim/filetype.vim:
aubufread,bufnewfile/etc/nginx/*,/usr/local/nginx/conf/* if &ft== ' |setfiletype nginx | endif
where "/etc/nginx" is the Nginx configuration file directory.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/57/9C/wKiom1SgC6ChfzPdAACKfwYld7Y863.jpg "style=" float: none; "title=" 18.png "alt=" Wkiom1sgc6chfzpdaackfwyld7y863.jpg "/>
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/57/99/wKioL1SgDFOTnmKLAAIZ8Qs0EKE325.jpg "style=" float: none; "title=" 19.png "alt=" Wkiol1sgdfotnmklaaiz8qs0eke325.jpg "/>
As shown, the Nginx.vim configuration is complete
Step Two: Establish the URL root directory of two virtual hosts:/WWW/80,/www/8080, and configure the default home page for both virtual hosts, corresponding to the main page content www.80.com, www.8080.com.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/57/9C/wKiom1SgC_LCJSA0AAGFk4Zb7S4051.jpg "title=" 20.png "alt=" Wkiom1sgc_lcjsa0aagfk4zb7s4051.jpg "/>
Step three: Fix nginx config file (config file path:/etc/nginx/nginx.conf), the configuration file is as follows
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/57/99/wKioL1SgDNLAhzivAAEBFutImQQ625.jpg "title=" 21.png "alt=" Wkiol1sgdnlahzivaaebfutimqq625.jpg "/>
Step Four: Test
(1) through the SS command view, 80, 8080 the two ports are open.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/57/99/wKioL1SgDQCSPLMSAAEgwznePhM442.jpg "title=" 22.png "alt=" Wkiol1sgdqcsplmsaaegwznephm442.jpg "/>
(2) using the browser, Access 172.16.249.96 8080, indicating successful access
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/57/9C/wKiom1SgDG-QawAJAACTjTHj0cM539.jpg "style=" float: none; "title=" 23.png "alt=" Wkiom1sgdg-qawajaactjthj0cm539.jpg "/>
(3) Use the browser, Access 172.16.249.96 80, and do not have access to their own set of 80-port virtual host default home page, and the display is installed with the default Web page (indicating a problem with the configuration file configuration)
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/57/99/wKioL1SgDSOg2qOZAAMGLIBC4lQ942.jpg "style=" float: none; "title=" 24.png "alt=" Wkiol1sgdsog2qozaamglibc4lq942.jpg "/>
(4) Troubleshooting: Look at the configuration in the configuration file nginx.conf, find the following configuration, include this configuration, indicating that the/ETC/CONF.D, directory under the. conf end of the configuration file is also imported.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/57/99/wKioL1SgDWHRG0KzAADLr51tLwA805.jpg "title=" 27.png "alt=" Wkiol1sgdwhrg0kzaadlr51tlwa805.jpg "/>
(5) A default virtual host is configured in the default.conf configuration file under/ETC/NGINX/CONF.D, renaming this profile so that it cannot be read in by the master configuration file
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/57/9C/wKiom1SgDPfS7r65AAD4xp6mjVA424.jpg "title=" 25.png "alt=" Wkiom1sgdpfs7r65aad4xp6mjva424.jpg "/>
(6) Using the browser, access the 172.16.249.96 80, indicating that the configuration was successful.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/57/99/wKioL1SgDcnR4J1UAACKOM7oh4Q077.jpg "title=" 26.png "alt=" Wkiol1sgdcnr4j1uaackom7oh4q077.jpg "/>
2, the source code to compile the installation Nginx, and configure IP-based virtual host
Configuration requirements: The host IP address is 172.16.249.96, 172.16.249.95, and then each of these two IP addresses are based on the IP address of the virtual host.
Step one: Establish the URL root directory of two virtual hosts:/WWW/96,/www/95, the content of the main page is 172.16.249.96 and 172.16.249.95
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/57/9C/wKiom1SgDdmBOVQNAAHtfZBHSh4697.jpg "title=" 28.png "alt=" Wkiom1sgddmbovqnaahtfzbhsh4697.jpg "/>
Step Two: Configure two IP addresses for the host one for: 172.16.249.96, 172.16.249.95
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/57/99/wKioL1SgDrHBVDiHAAVVNSV7oyk508.jpg "title=" 29.png "alt=" Wkiol1sgdrhbvdihaavvnsv7oyk508.jpg "/>
Step Three: Modify the configuration file to configure the IP-based virtual host.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/57/9C/wKiom1SgDi_Cc4JjAAFQetGpu-k363.jpg "title=" 30.png "alt=" Wkiom1sgdi_cc4jjaafqetgpu-k363.jpg "/>
Step four: Use the browser to test, in the client using the browser through IP access to this, two IP, to see if it is the corresponding default home page.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/57/9C/wKiom1SgDlmCCwf7AAE6kJBP9dc467.jpg "title=" 31.png "alt=" Wkiom1sgdlmccwf7aae6kjbp9dc467.jpg "/>
The following results indicate that the IP-based virtual host configuration was successful.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/57/99/wKioL1SgDzmRDIE3AAB9sdi8PTc086.jpg "style=" float: none; "title=" 32.png "alt=" Wkiol1sgdzmrdie3aab9sdi8ptc086.jpg "/>
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/57/9C/wKiom1SgDoehGpjaAABxVvjTvfo283.jpg "style=" float: none; "title=" 33.png "alt=" Wkiom1sgdoehgpjaaabxvvjtvfo283.jpg "/>
3, source code to install Nginx, and configure the domain-based virtual host
Configuration requirements: Configure two domain names for www1.stu1.com, and www2.stu1.com two virtual hosts, the corresponding URL root path is:/WEB/VHOST/WWW1,/web/vhost/www2. and set up the corresponding default home page in these two root directories, the information of the homepage is www1.stu1.com, www2.stu1.com, respectively.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/57/99/wKioL1SgD77TXWSuAAH79uR0ZSw285.jpg "title=" 34.png "alt=" Wkiol1sgd77txwsuaah79ur0zsw285.jpg "/>
Step Two: Modify the configuration file, configure the domain-based virtual host
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/57/99/wKioL1SgD_2BAhglAAEKLVDUMAg134.jpg "title=" 39.png "alt=" Wkiol1sgd_2bahglaaeklvdumag134.jpg "/>
Step three: With 172.16.249.65 this Linux host using the Curl tool to test, before testing must first configure the/etc/hosts file, can resolve the two domain names www1.stu1.com and www2.stu1.com
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/57/99/wKioL1SgEDXh1rRSAARKnGvREEQ907.jpg "title=" 36.png "alt=" Wkiol1sgedxh1rrsaarkngvreeq907.jpg "/>650) this.width=650; src=" http://s3.51cto.com/wyfs02/M02/57/9C/ Wkiom1sgd5dbdqfxaafu3wqmhfa894.jpg "title=" 37.png "alt=" Wkiom1sgd5dbdqfxaafu3wqmhfa894.jpg "/>
The test results show that Nginx domain-based virtual host configuration is successful.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/57/99/wKioL1SgEFvAeGKkAADY_k7UNgU082.jpg "title=" 38.png "alt=" Wkiol1sgefvaegkkaady_k7ungu082.jpg "/>
Configuration of Nginx virtual host for Linux notes