Install Nginx in Ubuntu

Source: Internet
Author: User
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:

  1. #! /Bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: nginx
  4. # Required-Start:
  5. # Required-Stop:
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: nginx
  9. # Description: nginx server
  10. ### END INIT INFO
  11. ./Lib/lsb/init-functions
  12. PROGRAM =/usr/nginx/sbin/nginx
  13. Test-x $ PROGRAM | exit 0
  14. Case "$1" in
  15. Start)
  16. Log_begin_msg "Starting Nginx server"
  17. /Usr/nginx/sbin/nginx
  18. Log_end_msg 0
  19. ;;
  20. Stop)
  21. PID = 'cat/usr/nginx/logs/nginx. Pi'
  22. Log_begin_msg "Stopping Nginx server"
  23. If [! -Z "$ PID"]; then
  24. Kill-15 $ PID
  25. Fi
  26. Log_end_msg 0
  27. ;;
  28. Status)
  29. ;;
  30. *)
  31. Log_success_msg "Usage: service nginx {start | stop | status }"
  32. Exit 1
  33. Esac
  34. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.