|
CentOS 6.5 installation and simple configuration Nginx
First, Preparation
(1) because nginx need to access port 80 so turn off the firewall or open ports, and selinux.
Command Reference
Turn off the firewall:
[Root @ local ~] # iptables -I INPUT -p tcp --dport 80 -j ACCEPT
[Root @ local ~] # service iptables save
Close selinux:
[Root @ local ~] # setenforce 0
[Root @ local ~] # vim / etc / selinux / config
The SELINUX = enforcing to SELINUX = disabled
(2) If the domain name is used to build their own DNS service
Second, the installation
(1) needs to be installed to run because nginx pcre, zlib packages, etc., so we installed
Pcre = Pcre Compatible Regular Expressions
[Root @ local ~] yum -y install pcre * zlib * # or compile and install
[Root @ local ~] # useradd -M -s / sbin / nologin nginx # Create nginx service
Launching User
(3) compile and install nginx, download address: http: //nginx.org/en/download.html install the latest stable version of nginx-1.8.0
[Root @ local ~] # tar zxf nginx-1.8.0.tar.gz
[Root @ local ~] # cd nginx-1.8.0
[Root @ local nginx-1.8.0] # ls
auto CHANGES.ru configure html Makefile objs src
CHANGES conf contrib LICENSE man README
[Root @ local nginx-1.8.0] # ./configure --user = nginx --group = nginx --prefix = / application / nginx-1.8.0 --with-http_stub_status_module --with-http_ssl_module #. / Configure parameter Description -help
[Root @ local nginx-1.8.0] # make
[Root @ local nginx-1.8.0] # make install
(4) production of soft connection
[Root @ local nginx-1.8.0] #ln -a /application/nginx-1.8.0/
/ Application / nginx
(5) Basic Usage
# Syntax check
[Root @ local nginx-1.8.0] # / application / nginx / sbin / nginx -t
nginx: the configuration file /application/nginx-1.8.0/conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.8.0/conf/nginx.conf test is successful
# Start Service
[Root @ local nginx-1.8.0] # / application / nginx / sbin / nginx
# Port inspection
[Root @ local nginx-1.8.0] # netstat -lnt
# Inspection process
[Root @ local nginx-1.8.0] # ps -ef | grep nginx # port information is stored in
/ Application / nginx / logs / nginx.pid file
# View port occupied by process
[Root @ local nginx-1.8.0] # lsof -i: 80
# Error log
/application/nginx/logs/error.log
Third, write a script nginx service
In order to facilitate usage by server to start, close, open, reload nginx service so we have to compile
Write nginx service script (script I have written for informational purposes only!)
[Root @ local ~] # vim /etc/init.d/nginx
#! / Bin / bash
#chkconfig: - 99 20
#description: Nginx Server Contorl Script
PROG = "/ application / nginx / sbin / nginx"
PIDF = "/ application / nginx / logs / nginx.pid"
ok = `echo -e" \ e [1; 31m [ok] \ e [0m "`
no = `echo -e" \ e [1; 31m [no] \ e [0m "`
detection = `/ application / nginx / sbin / nginx -t 2> & 1`
screen_1 = `echo $ detection | awk '{print $ 6, $ 7, $ 8}'`
screen_2 = `echo $ detection | awk '{print $ 13, $ 14, $ 15}'`
if [ "$ screen_1" = "syntax is ok"] && [ "$ screen_2" = "test is successful"];
then
case "$ 1" in
start)
$ PROG
echo "Nginx Is starting state $ ok"
;;
stop)
kill -s QUIT $ (cat $ PIDF)
echo "Nginx Is closing state $ ok"
;;
restart)
$ 0 stop
$ 0 start
echo "Nginx Is to restart state $ ok"
;;
reload)
kill -s HUP $ (cat $ PIDF)
echo "Nginx Is overloaded state $ ok"
;;
*)
echo "Usage: $ 0 (start | stop | restart | reload)"
exit 1
esac
else
echo "Nginx check state $ no"
echo "Please check the configuration file"
echo "$ detection"
fi
exit 0
[Root @ local ~] # chmod + x /etc/init.d/nginx
[Root @ local ~] # chkconfig -add nginx # add a system service
[Root @ local ~] # chkconfig nginx on
Fourth, simple nginx web site
Nginx default site directory is the installation html directory here (/ application / nginx / html)
In the main configuration file /application/nginx/conf/nginx.conf view, redeployed for web pages
Just / application / nginx / html / index.html in to replace
The main configuration file to explain
[Root @ local ~] # egrep -v "# | ^ $" /application/nginx/conf/nginx.conf
worker_processes 1; # specify the number of processes open Nginx
events {# set Nginx operating mode and on-line connections
worker_connections 1024;
}
http {
include mime.types; # main module commands implementation sets the configuration file that contains all files
default_type application / octet-stream; # http belong core module command, located here
Type set to binary, that is, when the file type is not defined in this way, for example, no PHP
Environment, nginx is not given to resolve, this time, to access a PHP file browser download window will appear.
sendfile on; # for efficient file transfer mode
keepalive_timeout 65; set the client request header file read timeout, if more than this
Between the server closes the connection.
Keyword server {# define virtual host begins
listen 80; # is used to specify the virtual host port services
Used to specify the ip address or domain, multiple domain names separated by spaces; server_name localhost
location / {
root html;
index index.html index.htm; # is used to set the default home page to access
}
error_page 500 502 503 504 /50x.html;# static pages redirect server error
Page, such as page Ctrip's website crashes occur
location = /50x.html {
root html;
}
}
} |
|
|
|