Nginx configuration and application of virtual host

Source: Internet
Author: User

One, nginx configuration file is divided into three parts, global configuration, I/O event configuration and HTTP configuration. "#" represents a comment, ending with ";" at the end of the configuration item


    1. The global configuration includes nginx running user, number of working process, error log, PID storage location and other basic information

650) this.width=650; "src=" http://s4.51cto.com/wyfs02/M01/7B/64/wKioL1bNEOnQNu00AABP_94ymKo172.jpg "title=" Global. jpg "alt=" Wkiol1bneonqnu00aabp_94ymko172.jpg "/>

Here the working process defaults to 1, if the server has more than one CPU or a multi-core processor, we can modify the number of worker processes to be the same as the number of CPU cores, but if the site traffic demand is not large, generally set to 1 is enough


2.I/O event configuration, using "events {}" to delimit the tag, to specify the nginx process I/O corresponding module, the number of links not a process, and so on. For versions 2.6 and above, it is recommended to use the Epoll model to improve performance; The number of connections per process is based on actual needs, typically below 10000, and 1024 by default.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/7B/65/wKiom1bNEIni3bUbAAAkoiIiGxg095.jpg "title=" Events.jpg "alt=" Wkiom1bneini3bubaaakoiiigxg095.jpg "/>


3.HTTP configuration, using "http {}" to delimit tags, including access logs, HTTP port, web directory, default character set, connection hold and its virtual host, PHP parsing, and a series of settings, most of which are included in the sub-definition tag "server {}"

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/7B/66/wKiom1bNGu-B3dmUAAEqIkLI17U776.jpg "title=" Http.jpg "alt=" Wkiom1bngu-b3dmuaaeqikli17u776.jpg "/>

If you want to make changes to find the corresponding configuration item modification, then restart the Nginx service after modification


Second, the domain-based virtual web host

1. First we create two test pages for testing

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/7B/66/wKiom1bNHD7RmJzhAABX6jJkXMg474.jpg "title=" Test page. jpg "alt=" wkiom1bnhd7rmjzhaabx6jjkxmg474.jpg "/>


2. Next, modify the Nginx configuration file, add the following two server configuration items in the HTTP configuration, Note: the "{}" of the server configuration item must be paired, and end with ";" at the end of each line of configuration item, save exit and restart Nginx service

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/7B/66/wKiom1bNF52QmbOcAADYfPkYsL0117.jpg "title=" Virtual web.jpg "alt=" Wkiom1bnf52qmbocaadyfpkysl0117.jpg "/>


3. Test, use domain name to access two websites, see if it can be used properly

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/7B/66/wKiom1bNHHnySMpKAAB4SCNU_mI209.jpg "title=" Test 1.jpg "alt=" Wkiom1bnhhnysmpkaab4scnu_mi209.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/7B/65/wKioL1bNHPPSxTCVAACA2Y_S2Vg966.jpg "title=" Test 2.jpg "alt=" Wkiol1bnhppsxtcvaaca2y_s2vg966.jpg "/>

Nginx configuration and application of virtual host

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.