1. Preparatory work
Choose to install the software first: Gcc,pcre (Perl Compatible Regular Expression), Zlib,openssl.
Nginx is written in C, need to compile with GCC, Nginx rewrite and HTTP module will use the Pcre;nginx in the gzip used to zlib;
Use the command "# gcc" to see if GCC is installed, and if "Gcc:no input Files" message appears, the instructions are already installed.
Otherwise, you'll need to install it with the command "# yum install gcc"! You may need to enter Y multiple times to confirm.
Once installed, you can then use the command "#gcc" test, or use the command "# gcc-v" to view its version number.
In the same way, install PCRE,ZLIB,OPENSSL with the following command (where Devel is the meaning of the Develop development package):
- # yum Install-y pcre Pcre-devel
- # yum Install-y zlib zlib-devel
- # yum Install-y OpenSSL Openssl-devel
2. Download and install
Create a directory (NGINX-SRC) and go in; Then, download, unzip, configure, compile, install from the official address (http://nginx.org/):
- # mkdir nginx-src && CD nginx-src
- # wget http://nginx.org/download/nginx-1.7.3.tar.gz
- # tar Xzf nginx-1.7.3.tar.gz
- # CD nginx-1.7.3
- #./configure
- # make
- # make Install
- # Whereis Nginx
- Nginx:/usr/local/nginx
The default installation path is:/usr/local/nginx; jump to its directory under the Sbin path, you can start or stop it.
- #./nginx-h
- Nginx version:nginx/1.7.3
- Usage:nginx [-?HVVTQ] [-s signal] [-c filename] [-p prefix] [-g directives]
- Options:
- -?,-H:this Help
- -v:show Version and exit
- -v:show version and configure options then exit
- -t:test Configuration and exit
- -q:suppress non-error messages during configuration testing
- -S signal:send signal to a master process:stop, quit, reopen, reload
- -P prefix:set Prefix path (default:/usr/local/nginx/)
- -C filename:set configuration file (default:conf/nginx.conf)
- -G Directives:set Global directives out of configuration file
Start: Nginx
Stop: Nginx-s stop
3. Add to System service
Using the command "# Vi/etc/init.d/nginx", open the editor and enter the following:
- #!/bin/sh
- # chkconfig:2345 85 15
- # Startup script for the Nginx Web Server
- # Description:nginx is a world Wide Web server.
- # It's used to serve HTML files and CGI.
- # Processname:nginx
- # Pidfile:/usr/local/nginx/logs/nginx.pid
- # config:/usr/local/nginx/conf/nginx.conf
- Path=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
- desc= "Nginx Deamon"
- Name=nginx
- daemon=/usr/local/nginx/sbin/$NAME
- Scriptname=/etc/init.d/$NAME
- Test-x $DAEMON | | Exit 0
- D_start () {
- $DAEMON | | Echo-n "Already Running"
- }
- D_stop () {
- $DAEMON-S Quit | | Echo-n "Not Running"
- }
- D_reload () {
- $DAEMON-S Reload | | Echo-n "Can not reload"
- }
- Case "$" in
- Start
- Echo-n "Starting DESC:desc:name"
- D_start
- echo "."
- ;;
- Stop
- Echo-n "Stopping DESC:desc:name"
- D_stop
- echo "."
- ;;
- Reload
- Echo-n "Reloading $DESC conf ..."
- D_reload
- echo "Reload."
- ;;
- Restart
- Echo-n "Restarting DESC:desc:name"
- D_stop
- Sleep 2
- D_start
- echo "."
- ;;
- *)
- echo "Usage: $ScRIPTNAME {start|stop|reload|restart}" >&2
- Exit 3
- ;;
- Esac
- Exit 0
After you save the exit, use the following command to make it executable, and then add the configuration and view it.
You can modify its value with Chkconfig, or you can change the self-boot by using the Ntsysv tool.
- # chmod +x/etc/init.d/nginx
- # chkconfig--add Nginx
- # chkconfig Nginx on/off
- # chkconfig--list Nginx
- Nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off
Under Linux (CentOS), download and install Nginx and configure