Configure Nginx Web server steps in Linux

Source: Internet
Author: User

System Environment: CENTOS7

Software Required: nginx-1.3.16.tar.gz libevent-2.0.21-stable.tar.gz Pcre and Pcre-devel

Nginx:http://nginx.org/download/nginx-1.3.16.tar.gz

Libevent:http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz

Project 1: Installing nginx and configuring the Environment

Step 1: Install Pcre-devel, and build Nginx user

# yum Install Pcre-devel

# groupadd-r Nginx

# Useradd-r-G nginx-m nginx

Step 2: Unzip the source of Nginx and install

# TAR-ZXVF Nginx-1.3.16.tar.gz-c/usr/local/src/

# cd/usr/local/src/nginx-1.3.16/

#./configure \

--conf-path=/etc/nginx/nginx.conf \

--error-log-path=/var/log/nginx/error.log \

--http-log-path=/var/log/nginx/access.log \

--pid-path=/var/run/nginx/nginx.pid \

--lock-path=/var/lock/nginx.lock \

--user=nginx \

--group=nginx \

--with-http_ssl_module \

--with-http_flv_module \

--with-http_stub_status_module \

--with-http_gzip_static_module \

--http-client-body-temp-path=/var/tmp/nginx/client/\

--http-proxy-temp-path=/var/tmp/nginx/proxy/\

--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/\

--with-pcre

# Make && make install

# mkdir-p/var/tmp/nginx/client

Step 3: Start the Nginx service and test on the client

#/usr/local/nginx/sbin/nginx

Enter the native IP on the browser

Project 2: Implementing a Virtual Host

Step 1: Preparing for work

# ifconfig eth0:0 192.168.111.20

Create Two site directories

# mkdir/website1

# Mkdir/website2

Set up two directories to store logs

# mkdir/var/log/nginx/website1

# Mkdir/var/log/nginx/website2

Create a two test page

# echo "This is WebSite1" >/website1/index.html

# echo "This is Website2" >/website2/index.html

Step 2: Modify the configuration file, the original configuration file has a server node by default, modify it, and then add a server node

server {

Listen 192.168.111.10:80;

server_name localhost;

#charset Koi8-r;

Access_log/var/log/nginx/website1/access.log;

Error_log/var/log/nginx/website1/error.log;

Location/{

root/website1;

Index index.html index.htm;

}

Error_page 404/404.html;

# REDIRECT Server error pages to the static page/50x.html

#

Error_page 502 503 504/50x.html;

Location =/50x.html {

root HTML;

}

}

server {

Listen 192.168.111.20:80;

server_name localhost;

#charset Koi8-r;

Access_log/var/log/nginx/website2/access.log;

Error_log/var/log/nginx/website2/error.log;

Location/{

Root/website2;

Index index.html index.htm;

}

Error_page 404/404.html;

# REDIRECT Server error pages to the static page/50x.html

#

Error_page 502 503 504/50x.html;

Location =/50x.html {

root HTML;

}

}

This file in the Nginx installation directory in the Conf inside the nginx.conf inside modify

Step 3:s use./nginx-s Reload re-installed in the configuration

Inside the terminal, enter the sbin in the Nginx directory, and then use the:./nginx-s reload command to reload the configuration

Configure Nginx Web server steps in Linux

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.