Under Linux (CentOS), download and install Nginx and configure

Source: Internet
Author: User

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):

    1. # yum Install-y pcre Pcre-devel
    2. # yum Install-y zlib zlib-devel
    3. # 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/):

    1. # mkdir nginx-src && CD nginx-src
    2. # wget http://nginx.org/download/nginx-1.7.3.tar.gz
    3. # tar Xzf nginx-1.7.3.tar.gz
    4. # CD nginx-1.7.3
    5. #./configure
    6. # make
    7. # make Install
    8. # Whereis Nginx
    9. 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.

  1. #./nginx-h
  2. Nginx version:nginx/1.7.3
  3. Usage:nginx [-?HVVTQ] [-s signal] [-c filename] [-p prefix] [-g directives]
  4. Options:
  5. -?,-H:this Help
  6. -v:show Version and exit
  7. -v:show version and configure options then exit
  8. -t:test Configuration and exit
  9. -q:suppress non-error messages during configuration testing
  10. -S signal:send signal to a master process:stop, quit, reopen, reload
  11. -P prefix:set Prefix path (default:/usr/local/nginx/)
  12. -C filename:set configuration file (default:conf/nginx.conf)
  13. -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:

  1. #!/bin/sh
  2. # chkconfig:2345 85 15
  3. # Startup script for the Nginx Web Server
  4. # Description:nginx is a world Wide Web server.
  5. # It's used to serve HTML files and CGI.
  6. # Processname:nginx
  7. # Pidfile:/usr/local/nginx/logs/nginx.pid
  8. # config:/usr/local/nginx/conf/nginx.conf
  9. Path=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  10. desc= "Nginx Deamon"
  11. Name=nginx
  12. daemon=/usr/local/nginx/sbin/$NAME
  13. Scriptname=/etc/init.d/$NAME
  14. Test-x $DAEMON | | Exit 0
  15. D_start () {
  16. $DAEMON | | Echo-n "Already Running"
  17. }
  18. D_stop () {
  19. $DAEMON-S Quit | | Echo-n "Not Running"
  20. }
  21. D_reload () {
  22. $DAEMON-S Reload | | Echo-n "Can not reload"
  23. }
  24. Case "$" in
  25. Start
  26. Echo-n "Starting DESC:desc:name"
  27. D_start
  28. echo "."
  29. ;;
  30. Stop
  31. Echo-n "Stopping DESC:desc:name"
  32. D_stop
  33. echo "."
  34. ;;
  35. Reload
  36. Echo-n "Reloading $DESC conf ..."
  37. D_reload
  38. echo "Reload."
  39. ;;
  40. Restart
  41. Echo-n "Restarting DESC:desc:name"
  42. D_stop
  43. Sleep 2
  44. D_start
  45. echo "."
  46. ;;
  47. *)
  48. echo "Usage: $ScRIPTNAME {start|stop|reload|restart}" >&2
  49. Exit 3
  50. ;;
  51. Esac
  52. 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.

        1. # chmod +x/etc/init.d/nginx
        2. # chkconfig--add Nginx
        3. # chkconfig Nginx on/off
        4. # chkconfig--list Nginx
        5. Nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off

Under Linux (CentOS), download and install Nginx and configure

Related Article

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.