DownloadNginx latest stable version: Download Nginx latest stable version from here
You can download the latest http://nginx.org/en/download.html from here, such as: nginx-1.0.6.tar.gz
Compile and install
Assume that the downloaded file is in the/usr/local/src directory.
Tar zxvf nginx-1.0.6.tar.gz
Cd nginx-1.0.6
./Configure-prefix =/usr/nginx
Make
Make install
The file will be installed in the/usr/nginx directory.
Run sudo./nginx in the/usr/nginx/sbin/directory to start nginx.
Static File Server Construction
Add the following configuration location ~ to the/usr/nginx/conf/nginx. conf file ~ ^/(Images | javascript | js | css | flash | media | static)/{root/opt/resources; expires 1d ;}
Create the/opt/resources Directory and copy the css, images, and other folders to the following directory. Add the logo.gif image to the imagesdirectory. After nginx is started, you can view the following method: http: // localhost/images/logo.gif
Create System Service
Cd/etc/init. d/
Create an nginx script with the following content:
- #! /Bin/sh
- ### BEGIN INIT INFO
- # Provides: nginx
- # Required-Start:
- # Required-Stop:
- # Default-Start: 2 3 4 5
- # Default-Stop: 0 1 6
- # Short-Description: nginx
- # Description: nginx server
- ### END INIT INFO
- ./Lib/lsb/init-functions
- PROGRAM =/usr/nginx/sbin/nginx
- Test-x $ PROGRAM | exit 0
- Case "$1" in
- Start)
- Log_begin_msg "Starting Nginx server"
- /Usr/nginx/sbin/nginx
- Log_end_msg 0
- ;;
- Stop)
- PID = 'cat/usr/nginx/logs/nginx. Pi'
- Log_begin_msg "Stopping Nginx server"
- If [! -Z "$ PID"]; then
- Kill-15 $ PID
- Fi
- Log_end_msg 0
- ;;
- Status)
- ;;
- *)
- Log_success_msg "Usage: service nginx {start | stop | status }"
- Exit 1
- Esac
- Exit 0
Then run the following command:
Sudo chmod + x./nginx
Sudo update-rc.d nginx defaults
Now you can use the following command to restart nginx.
Sudo service nginx start
Sudo service nginx stop