Ubuntu12.10ServerNginx product installation

Source: Internet
Author: User
The source code is always downloaded from the Nginx site for compilation and installation, from manual mode to automatic script. However, if you want to deploy multiple machines, this method is obviously not good, so do not drag the deployment into code compilation. So today I tried the Ubuntu installation package. After executing apt-getinstallnginx, nginx is automatically installed and the startup script is created. Run nginx-v to find that the version is 1.2.1, which is not bad. Run nginx-V to observe the loaded module.

The source code is always downloaded from the Nginx site for compilation and installation, from manual mode to automatic script. However, if you want to deploy multiple machines, this method is obviously not good, so do not drag the deployment into code compilation.

So today I tried the Ubuntu installation package.

After executing apt-get install nginx, nginx is automatically installed and the startup script is created.

Run nginx-v to find that the version is 1.2.1, which is not bad.

Run nginx-V to check the loaded module and find the http_ssl module.

With-http_ssl_module

Everything is good. The complete configuration parameters are as follows:

  1. Nginx-V
  2. Nginx version: nginx/1.2.1
  3. Tls sni support enabled
  4. Configure arguments: -- prefix =/etc/nginx -- conf-path =/etc/nginx. conf -- error-log-path =/var/log/nginx/error. log -- http-client-body-temp-path =/var/lib/nginx/body -- http-fastcgi-temp-path =/var/lib/nginx/fastcgi -- http- log-path =/var/log/nginx/access. log -- http-proxy-temp-path =/var/lib/nginx/proxy -- http-scgi-temp-path =/var/lib/nginx/scgi -- http-uwsgi- temp-path =/var/lib/nginx/uwsgi -- lock-path =/var/lock/nginx. lock -- pid-path =/var/run/nginx. pid -- with-pcre-jit -- with-debug -- with-http_addition_module -- with-http_dav_module -- with-http_geoip_module -- with-http_gzip_static_module -- with-http_image_filter_module -- with-http_realip_module -- with-http_stub_status_module -- with-http_ssl_module -- with-http_sub_module -- with-http_xslt_module -- with-ipv6 =/usr/include /openssl -- with-md5 =/usr/include/openssl -- with-mail -- with-mail_ssl_module -- add-module =/build/buildd/nginx-1.2.1/debian/modules/nginx-auth-pam -- add -module =/build/buildd/nginx-1.2.1/debian/modules/nginx-echo -- add-module =/build/buildd/nginx-1.2.1/debian/modules/nginx-upstream-fair -- add -module =/build/buildd/nginx-1.2.1/debian/modules/nginx-dav-ext-module

Let's look at the/etc/init. d/nginx script:

  1. #! /Bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: nginx
  4. # Required-Start: $ local_fs $ remote_fs $ network $ syslog
  5. # Required-Stop: $ local_fs $ remote_fs $ network $ syslog
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: starts the nginx web server
  9. # Description: starts nginx using start-stop-daemon
  10. ### END INIT INFO
  11. PATH =/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  12. DAEMON =/usr/sbin/nginx
  13. NAME = nginx
  14. DESC = nginx
  15. # Include nginx defaults if available
  16. If [-f/etc/default/nginx]; then
  17. ./Etc/default/nginx
  18. Fi
  19. Test-x $ DAEMON | exit 0
  20. Set-e
  21. ./Lib/lsb/init-functions
  22. Test_nginx_config (){
  23. If $ DAEMON-t $ DAEMON_OPTS>/dev/null 2> & 1; then
  24. Return 0
  25. Else
  26. $ DAEMON-t $ DAEMON_OPTS
  27. Return $?
  28. Fi
  29. }
  30. Case "$1" in
  31. Start)
  32. Echo-n "Starting $ DESC :"
  33. Test_nginx_config
  34. # Check if the ULIMIT is set in/etc/default/nginx
  35. If [-n "$ ULIMIT"]; then
  36. # Set the ulimits
  37. Ulimit $ ULIMIT
  38. Fi
  39. Start-stop-daemon -- start -- quiet -- pidfile/var/run/$ NAME. pid \
  40. -- Exec $ DAEMON -- $ DAEMON_OPTS | true
  41. Echo "$ NAME ."
  42. ;;
  43. Stop)
  44. Echo-n "Stopping $ DESC :"
  45. Start-stop-daemon -- stop -- quiet -- pidfile/var/run/$ NAME. pid \
  46. -- Exec $ DAEMON | true
  47. Echo "$ NAME ."
  48. ;;
  49. Restart | force-reload)
  50. Echo-n "Restarting $ DESC :"
  51. Start-stop-daemon -- stop -- quiet -- pidfile \
  52. /Var/run/$ NAME. pid -- exec $ DAEMON | true
  53. Sleep 1
  54. Test_nginx_config
  55. # Check if the ULIMIT is set in/etc/default/nginx
  56. If [-n "$ ULIMIT"]; then
  57. # Set the ulimits
  58. Ulimit $ ULIMIT
  59. Fi
  60. Start-stop-daemon -- start -- quiet -- pidfile \
  61. /Var/run/$ NAME. pid -- exec $ DAEMON -- $ DAEMON_OPTS | true
  62. Echo "$ NAME ."
  63. ;;
  64. Reload)
  65. Echo-n "Reloading $ DESC configuration :"
  66. Test_nginx_config
  67. Start-stop-daemon -- stop -- signal HUP -- quiet -- pidfile/var/run/$ NAME. pid \
  68. -- Exec $ DAEMON | true
  69. Echo "$ NAME ."
  70. ;;
  71. Configtest | testconfig)
  72. Echo-n "Testing $ DESC configuration :"
  73. If test_nginx_config; then
  74. Echo "$ NAME ."
  75. Else
  76. Exit $?
  77. Fi
  78. ;;
  79. Status)
  80. Status_of_proc-p/var/run/$ NAME. pid "$ DAEMON" nginx & exit 0 | exit $?
  81. ;;
  82. *)
  83. Echo "Usage: $ NAME {start | stop | restart | reload | force-reload | status | configtest}"> & 2
  84. Exit 1
  85. ;;
  86. Esac
  87. Exit 0

The reload, force-reload, and configtest functions are much more complete than those previously written. Very good.

Nginx is installed in the/usr/sbin/directory.

The process id file is/var/run/nginx. pid.

If the variable $ ULIMIT is defined, it will be used as a parameter for the ulimit command, but it should not be defined by default.

Similarly, you can assign the DAEMON_OPTS variable to the startup parameter. The default value is.

A good BASIC script.

Note: you cannot use pidof nginx to find the process id. Instead, you should only read the content of the process id file:

  1.  
  2. Root @ sloop2:/etc/init. d # pidof nginx
  3.  
  4. 6639 6638 6637 6636 6635
  5. Root @ sloop2:/etc/init. d # cat/var/run/nginx. pid
  6. 6635

At this time, as many as five nginx servers are started, one master node and four workers.

  1.  
  2. Root @ sloop2:/etc/init. d # ps-def | grep nginx
  3.  
  4. Root 6635 1 0? 00:00:00 nginx: master process/usr/sbin/nginx
  5. Www-data 6636 6635 0? 00:00:00 nginx: worker process
  6. Www-data 6637 6635 0? 00:00:00 nginx: worker process
  7. Www-data 6638 6635 0? 00:00:00 nginx: worker process
  8. Www-data 6639 6635 0? 00:00:00 nginx: worker process

This is called the Master process model, which is better than the previous Single process model. The master initializes the configuration, creates a worker, receives the request, and forwards it to the worker for processing.

The number of workers can be configured. Generally, the number of CPU cores in the system-1 is better.

Where is the nginx configuration file? After running the whereis nginx command, you can see that it is in the/etc/nginx directory.

In the nginx. conf file, the second line is worker_processes settings. The default value is 4. Here I only have two CPU cores, so I set it to 1.

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.