To configure the Nginx web server in Linux, use linuxnginx
System Environment: centos7
Required Software: 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: Install Nginx and configure the environment
Step 1: Install pcre-devel and create nginx users
# Yum install pcre-devel
# Groupadd-r nginx
# Useradd-r-g nginx-M nginx
Step 2: Decompress the nginx source code 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. conf \
-- Error-log-path =/var/log/nginx/error. log \
-- Http-log-path =/var/log/nginx/access. log \
-- Pid-path =/var/run/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 perform a test on the client
#/Usr/local/nginx/sbin/nginx
Enter the local ip address in the browser
Project 2: Implement Virtual Host
Step 1: Preparations
# Ifconfig eth0: 0 192.168.111.20
Create two site Directories
# Mkdir/website1
# Mkdir/website2
Create two log storage Directories
# Mkdir/var/log/nginx/website1
# Mkdir/var/log/nginx/website2
Create two test pages
# Echo "This is website1">/website1/index.html
# Echo "This is website2">/website2/index.html
Step 2: modify the configuration file. By default, the original configuration file contains a server node. Modify the node and add another 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 500 502 503 x.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 500 502 503 x.html;
Location =/50x.html {
Root html;
}
}
This file is modified in Nginx. conf In the conf file under the nginx installation directory.
Step 3: Use./nginx-s reload to reload the configuration.
Enter sbin in the nginx directory in the terminal, and then use the:./nginx-s reload command to re-load the configuration.