1. Preparations
1.1. Install OpenSSL (search by yourself)
1.2, prepare pcre
The library pere is for nginx to support regular expressions. It is just prepared, not installed, to avoid errors in 64-bit systems.
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.30.tar.gz
tar -zxf pcre-8.30
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.30.tar.gz tar -zxf pcre-8.30 |
1.3. Prepare the zlib library It is also just preparation, not installation, in order to avoid errors in 64-bit systems.
wget http://sourceforge.net/projects/libpng/files/zlib/1.2.6/zlib-1.2.6.tar.gz/download
tar -zxf zlib-1.2.6.tar.gz
wget http://sourceforge.net/projects/libpng/files/zlib/1.2.6/zlib-1.2.6.tar.gz/download tar -zxf zlib-1.2.6.tar.gz |
2. Compile and install 2.1. Download and create a temporary directory
wget http://nginx.org/download/nginx-1.1.9.tar.gz
tar -zxf nginx-1.1.9.tar.gz
cd nginx-1.1.9
mkdir -p /var/tmp/nginx
wget http://nginx.org/download/nginx-1.1.9.tar.gz tar -zxf nginx-1.1.9.tar.gz cd nginx-1.1.9 mkdir -p /var/tmp/nginx |
2.2, compilation and installation
./configure –prefix=/usr/local/nginx \
–pid-path=/var/run/nginx.pid \
–lock-path=/var/lock/nginx.lock \
–with-http_ssl_module \
–with-http_dav_module \
–with-http_flv_module \
–with-http_realip_module \
–with-http_gzip_static_module \
–with-http_stub_status_module \
–with-mail –with-mail_ssl_module \
–with-pcre=../pcre-8.30 \
–with-zlib=../zlib-1.2.6 \
–with-debug \
–http-client-body-temp-path=/var/tmp/nginx/client \
–http-proxy-temp-path=/var/tmp/nginx/proxy \
–http-fastcgi-temp-path=/var/tmp/nginx/fastcgi \
–http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
–http-scgi-temp-path=/var/tmp/nginx/scgi
make && make install
ln -s /usr/local/nginx/sbin/nginx /usr/sbin/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
./configure –prefix=/usr/local/nginx \ –pid-path=/var/run/nginx.pid \ –lock-path=/var/lock/nginx.lock \ –with-http_ssl_module \ –with-http_dav_module \ –with-http_flv_module \ –with-http_realip_module \ –with-http_gzip_static_module \ –with-http_stub_status_module \ –with-mail –with-mail_ssl_module \ –with-pcre=../pcre-8.30 \ –with-zlib=../zlib-1.2.6 \ –with-debug \ –http-client-body-temp-path=/var/tmp/nginx/client \ –http-proxy-temp-path=/var/tmp/nginx/proxy \ –http-fastcgi-temp-path=/var/tmp/nginx/fastcgi \ –http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \ –http-scgi-temp-path=/var/tmp/nginx/scgi make && make install ln -s /usr/local/nginx/sbin/nginx /usr/sbin/ |
For reference: Nginx compilation parameter analysis
?prefix #nginx installation directory, default in /usr/local/nginx
?pid-path #pid query file location, the default is in the logs directory
?lock-path #lock file location, the default is in the logs directory
?with-http_ssl_module #Enable the HTTP SSL module to support HTTPS requests.
?with-http_dav_module #Open the WebDAV extension action module, which can specify permissions for files and directories
?with-http_flv_module #Support dragging and playing of FLV files
?with-http_realip_module #Support displaying real source IP address
?with-http_gzip_static_module #Pre-compressed files are checked before transmission to prevent files from being compressed repeatedly
?with-http_stub_status_module #Get some running status of nginx
?with-mail #Allow POP3/IMAP4/SMTP proxy module
?with-mail_ssl_module #Allow POP3/IMAP/SMTP to use SSL/TLS
?with-pcre=../pcre-8.11 #Note that the pcre path is not installed
?with-zlib=../zlib-1.2.5 #Pay attention to the uninstalled zlib path
?with-debug #Allow debug logging
?http-client-body-temp-path #client request temporary file path
?http-proxy-temp-path #Set http proxy temporary file path
?http-fastcgi-temp-path #Set http fastcgi temporary file path
?http-uwsgi-temp-path=/var/tmp/nginx/uwsgi #Set uwsgi temporary file path
?http-scgi-temp-path=/var/tmp/nginx/scgi #Set scgi temporary file path
2.3. Startup nginx script
Enter edit mode, type the following script content:
#!/bin/bash
#
#chkconfig: – 85 15
#description: Nginx is a World Wide Web server.
#processname: nginx
nginx=/usr/local/nginx/sbin/nginx
cOnf=/usr/local/nginx/conf/nginx.conf
case $1 in
start)
echo -n “Starting Nginx”
$nginx -c $conf
echo “done”
;;
stop)
Echo -n “Stopping Nginx”
killall -9 nginx
echo “done”
;;
test)
$nginx -t -c $conf
;;
reload)
echo -n “Reloading Nginx”
ps auxww | grep nginx | grep master | awk ‘{print $2}’ | xargs kill -HUP
echo “done”
;;
restart)
$0 stop
$0 start
;;
show)
ps -aux|grep nginx
;;
*)
Echo -n “Usage: $0 {start|restart|reload|stop|test|show}”
;;
esac
#!/bin/bash
#
#chkconfig: – 85 15
#description: Nginx is a World Wide Web server.
#processname: nginx
nginx=/usr/local/nginx/sbin/nginx
cOnf=/usr/local/nginx/conf/nginx.conf
case $1 in
start)
echo
-n “Starting Nginx”
$nginx
-c $conf
echo
“done”
;;
stop)
echo
-n “Stopping Nginx”
killall
-9 nginx
echo
“done”
;;
test)
$nginx
-t -c $conf
;;
reload)
echo
-n “Reloading Nginx”
ps
auxww | grep nginx | grep master | awk ‘{print $2}’ | xargs kill
-HUP
echo
“done”
;;
restart)
$0
stop
$0
start
;;
show)
ps
-aux|grep nginx
;;
*)
echo
-n “Usage: $0
{start|restart|reload|stop|test|show}”
;;
esac
After saving the above script, do the following
chmod +x /etc/init.d/nginx
chkconfig –add nginx
chkconfig nginx on
chmod +x /etc/init.d/nginx chkconfig –add nginx chkconfig nginx on |
Appendix: nginx virtual host configuration
server {
listen 80;
Server_name vps.xj123.info;
Location / {
root root html/vps;
index index.html index.htm;
}
}
server { listen 80; server_name vps.xj123.info; location / { root html/vps; index index.html index.htm; } } |
Tip: You can use nginx -t to check whether there is a problem with the syntax, as shown in the figure:
nbsp;
echo
-n “Reloading Nginx”
ps
auxww | grep nginx | grep master | awk ‘{print $2}’ | xargs kill
-HUP
echo
“done”
;;
restart)
$0
stop
$0
start
;;
show)
ps
-aux|grep nginx
;;
*)
echo
-n “Usage: $0
{start|restart|reload|stop|test|show}”
;;
esac
After saving the above script, do the following
chmod +x /etc/init.d/nginx
chkconfig –add nginx
chkconfig nginx on
chmod +x /etc/init.d/nginx chkconfig –add nginx chkconfig nginx on |
Appendix: nginx virtual host configuration
server {
listen 80;
Server_name vps.xj123.info;
Location / {
root root html/vps;
index index.html index.htm;
}
}
server { listen 80; server_name vps.xj123.info; location / { root html/vps; index index.html index.htm; } } |
Tip: You can use nginx -t to check whether there is a problem with the syntax, as shown in the figure: