There are three ways to install software under Linux, and here I build the source code to install the main. After the server is minimized, install the dependent packages.
For administrative and security purposes, we want to run our Web server using a specified normal user identity. So, we first add an ordinary user to run our nginx.
[[email protected] ~]# groupadd nginx [[email protected] ~]# useradd-g Nginx
Shut down the system firewall,
[[Email protected] ~]# service iptables stop [[email protected] ~]# chkconfig iptables off
1. Download the latest stable version and install Nginx
Then download, unzip and compile the installation of our Nginx, which is using the latest stable version,
[Email protected] ~]# wget http://nginx.org/download/nginx-1.8.0.tar.gz [[email protected] ~]# TAR-XF Nginx-1.8.0.tar.gz-c/USR/LOCAL/SRC [[email protected] ~]# cd/usr/local/src/nginx-1.8.0 [[email protected] nginx-1.8.0 ]#./configure--user=nginx--group=nginx--with-http_ssl_module--with-http_sub_module
The installation process is relatively straightforward, and the./configure process will report some dependencies, which are addressed here. First, the operating system is minimized, and GCC is not installed, so the first step is to do so./configure, it will be an error.
When the following error occurs, you need to install the development package for SSL.
./CONFIGURE:ERROR:SSL modules require the OpenSSL library. You can either don't enable the modules, or install the OpenSSL library into the system, or build the OpenSSL library STA Tically from the source with Nginx by using--with-openssl=<path> option.
When the following error occurs, you need to install the zlib development package.
./CONFIGURE:ERROR:SSL modules require the OpenSSL library. You can either don't enable the modules, or install the OpenSSL library into the system, or build the OpenSSL library STA Tically from the source with Nginx by using--with-openssl=<path> option.
[email protected] ~]# yum install-y pcre-devel [[email protected] ~]# yum install-y gcc [[email protected] ~]# Yum Inst All-y Zlib-devel [[email protected] ~]# Yum install-y openssl-devel
Let's take a look at the following./configure several commonly used parameters:
--prefix=<dir> Specifies the installation home directory, the default is/usr/local/nginx--user=<user> Specify the user identity, if not specified by default use nobody--group=< ;group> Specify group Identity--with-http_ssl_module enable HTTPS support
2. Nginx start, restart and stop
Once the installation is complete, we can start the Nginx,
[Email protected] ~]#/usr/local/nginx/sbin/nginx-c/usr/loca/nginx/conf/nginx.conf
-C is the main configuration file used to specify Nginx, and defaults to the/usr/loca/nginx/conf/nginx.conf file if not specified. After startup, you can use the PS and Netstat commands to see if the startup is successful.
[[email protected] ~]# ps -ef |grep nginxroot 1059 1 0 02:49 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/ local/nginx/conf/nginx.confnginx 1061 1059 0 02:49 ? 00:00:00 nginx: worker process root 1063 1013 0 02:49 pts/0 00:00:00 grep nginx[[email protected] ~]# Netstat -antupactive internet connections (servers and established) proto recv-q send-q local address foreign address state PID/Program name tcp 0 0 192.168.1.151:8080 0.0.0.0:* LISTEN 1059/nginx tcp 0 0 192.168.1.150:8080 0.0.0.0:* listen 1059/nginx tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1059/nginx tcp 0 0 0.0.0.0:22 0.0.0.0:* listen 801/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 877/master tcp 0 0 192.168.1.129:22 192.168.1.106:56004 established 1009/sshd tcp 0 0 :::22 :::* LISTEN 801/sshd tcp 0 0 ::1:25 :::* LISTEN 877/master udp 0 0 0.0.0.0:68 0.0.0.0:* 1007/dhclient
Start successfully, we can visit the homepage to verify,
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/6E/C0/wKiom1WE1hGzuAqzAAMO065f9_I122.jpg "title=" Nginx01.png "alt=" Wkiom1we1hgzuaqzaamo065f9_i122.jpg "/>
3. Nginx Startup script
Nginx does not provide a management script similar to the System V service, if we want to let Nginx start automatically when booting, you can execute the following command:
[Email protected] ~]# echo "/usr/local/nginx/sbin/nginx-c/usr/local/nginx/conf/nginx.conf" >>/etc/rc.local
Of course, if we love the service management script of System V, we can refer to the following script
[[Email protected] ~]# cat /etc/init.d/nginx #!/bin/sh## nginx - this script starts and stops the nginx daemon## chkconfig: - 85 15# description: nginx is an http (s) server, http (s) reverse # proxy and imap/pop3 proxy server# processname: nginx# config: /etc/nginx/nginx.conf# config: /etc/sysconfig/nginx# pidfile: /var/run/nginx.pid# source function library. /etc/rc.d/init.d/functions# source networking configuration. /etc/sysconfig/network# check that networking is up. [ "$NETWORKING" = "no" ] && exit 0nginx= "/usr/local/nginx/sbin/ Nginx "prog=$ (basename $nginx) nginx_conf_file="/usr/local/nginx/conf/nginx.conf "[ -f /etc/ sysconfig/nginx ] && . /etc/sysconfig/nginxlockfile=/var/lock/subsys/nginxstart () { [ -x $nginx ] | | exit 5 [ -f $NGINX _conf_file ] | | exit 6 echo -n $ "starting $prog: " daemon $nginx -c $NGINX _conf_file retval=$? echo [ $retval -eq 0 ] && touch $ lockfile return $retval}stop () { echo -n $ " stopping $prog: " killproc $prog -QUIT retval=$? echo [ $retval -eq 0 ] & & rm -f $lockfile return $retval killall -9 nginx}restart () &NBSp { configtest | | return $? stop sleep 1 Start}reload () { configtest | | return $? echo -n $ "reloading $prog: " killproc $nginx -hup retval=$? echo}force_reload () { restart}configtest () { $nginx -t -c $NGINX _conf_file}rh_status () { status $prog}rh_status_q () { rh_status >/dev/null 2>&1}case "$" in Start) rh_status_q && exit 0 $1 ;; stop) rh_status_q | | exit 0 $1 ;; restart|configtest) $1 ;; reload) rh_status_q | | exit 7 $1 ;; force-reload) force_reload ;; status) rh_status ;; condrestart|try-restart) rh_status_q | | exit 0 ;; *) echo $ "Usage: $0 {start |stop|status|restart|condrestart|try-restart|reload|force-reload|configtest} " exit 2esac
Finally, give the script an executable permission and then use the Chkconfig command to manage it.
[[email protected] ~]# chmod 755/etc/init.d/nginx[[email protected] ~]# chkconfig nginx on
When we make some changes to Nginx configuration file, we want to do a smooth restart without interrupting the current service, you can use the following command,
[[Email protected] ~]# service Nginx Reload
The reload function in the script first checks the configuration file in a syntax format, using the following command,
[Email protected] ~]#/usr/local/nginx/sbin/nginx-t-c/usr/local/nginx/conf/nginx.conf
When the syntax format is checked, a signal labeled 1 or HUP is issued to Nginx, which will close the old process, open a new process, and wait for the end of the service if a process is serving a user.
Of course, we can also use the service Nginx restart way to restart the services. Stop Nginx, direct service nginx stop, or kill off all nginx processes.
This article is from the "Tiandaochouqin" blog, make sure to keep this source http://lavenliu.blog.51cto.com/5060944/1663792
Nginx Source Code Installation