Cainiao nginx Source Code Analysis configuration and deployment Article (1) Implement nginx & amp; quot; Iloveyou & amp; quot;

Source: Internet
Author: User
Tags epoll

Cainiao nginx Source Code Analysis configuration and deployment (1) Implement nginx & quot; Iloveyou & quot;

Cainiao nginx Source Code Analysis configuration and deployment (1) manually configure nginx "I love you"

Author: Echo Chen (Chen Bin)

Email: chenb19870707@gmail.com

Blog: Blog.csdn.net/chen19870707

Date: Nov 7th, 2014

I still remember that in the CSDN account leakage events of the past few years, statistics showed that the programmer's account contains the most love. Here I also use it as a standard, in this article, we will explain how to use Nginx to build a simple Web server that displays "I love you" on one machine. Let's try it together.

1. Nginx package

The latest nginx development version is 1.7.7:

Linux: nginx-1.7.7.tar.gzWindows: nginx-1.7.7.zip

Stable version 1.6.2:

You can use your operating system and the preferred selection program package. Here, nginx-1.7.7.tar.gz is used inCentOs 1, 6.4In the operating system.

2. Download, decompress, and install Nginx

Download and decompress, nginx-1.7.7.tar.gzCentOs 1, 6.4For example:

   1: wget http://nginx.org/download/nginx-1.7.7.tar.gz
   2: tar zxvf nginx-1.7.7.tar.gz 

But do not rush to install after downloading and unzipping, because Nginx depends on a lot of software (gcc, g ++, make, libz-dev, libbz2-dev, libreadline-dev ), we assume that your Linux environment is "pure", so we will install these dependency packages below. Follow the steps below to install:

   1: yum install gcc -y
   2: yum install g++ -y
   3: yum install make -y
   4: yum install zlib-dev* -y
   5: yum install bzip2-dev* -y
   6: yum install readline-devel -y

This is some basic software, as well as the installation of PCRE. PCRE is short for "Perl Compatible Regular Expressions" and is a Regular expression library. Download, unzip, and install PCRE:

   1: wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.gz
   2: tar -zxvf pcre-8.36.tar.gz
   3: cd pcre-8.36.tar.gz
   4: ./configure
   5: make
   6: make install

Now, we can install nginx.

   1: tar -zxvf nginx-1.7.7.tar.gz
   2: cd nginx-1.7.7
   3: ./configure
   4: sudo make
   5: sudo make install
3. Nginx configuration file

Follow the above steps to install Nginx. Because we use the default configure, it will be installed in the/usr/local/nginx directory. The corresponding configuration file is/usr/local/nginx/conf/nginx. conf. Open the configuration file and see the structure as follows:

   1: ...
2: # working mode and maximum number of connections
   3: events
   4: {
5: # refer to the event model. use [kqueue | rtsig | epoll |/dev/poll | select | poll]; the epoll model is a high-performance network I/O model in the kernel of Linux 2.6 or later versions. If you are running on FreeBSD, use the kqueue model.
   6: use epoll;
7: # maximum number of connections to a single process (maximum number of connections = number of connections * Number of processes)
   8: worker_connections 65535;
   9: }
  10:  
11: # Set the http server and use its reverse proxy function to provide Load Balancing support
  12: http
  13: {
  14:     ...
15: # First Virtual Server
  16:    server {
17: # Listen to port 80 of 192.168.8.x
  18:         listen       80;
  19:         server_name  192.168.8.x;
  20:        }
  21: }
  22:  
The events module indicates the working mode and the maximum number of connections. The http module sets the http server and the server module indicates the virtual server. Here, the simple configuration is briefly listed, for more information about the configuration, see Nginx configuration file. conf explanation in Chinese.
4. Compile a simple Nginx Configuration

Create a/root/test_space directory to store our test page. Then, modify it directly in the default Nginx configuration file/usr/loca/nginx/conf/nginx. conf. Add a server module in http as follows:

   1: server {
   2:     listen      8011;
   3:     server_name localhost;
   4:     charset     utf-8;
   5:     location / {
   6:         alias   /root/test_space/;
   7:     }
   8: }

Listen indicates the listening port number, sever_name indicates the name of the web server (which can be a domain name, host, or IP address), and charset specifies the encoding character set, the location specifies the file directory of the web service through alias.

5. Start Nginx
   1: /usr/local/nginx/sbin/nginx 
   2: s -ef | grep nginx

If the following figure is displayed, the startup is successful:

6. Test

Create the following html file under/root/test_space:

   1: 
 
   2:    
 
   3:    <body>I love you!<body>
   4: 

Echo Chen: Blog.csdn.net/chen19870707

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.