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. Run apt-get...

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.

[Plain]
With-http_ssl_module
Everything is good. The complete configuration parameters are as follows:
[Plain]
Nginx-V
Nginx version: nginx/1.2.1
Tls sni support enabled
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:
[Plain]
#! /Bin/sh
 
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $ local_fs $ remote_fs $ network $ syslog
# Required-Stop: $ local_fs $ remote_fs $ network $ syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
### END INIT INFO
 
PATH =/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON =/usr/sbin/nginx
NAME = nginx
DESC = nginx
 
# Include nginx defaults if available
If [-f/etc/default/nginx]; then
./Etc/default/nginx
Fi
 
Test-x $ DAEMON | exit 0
 
Set-e
 
./Lib/lsb/init-functions
 
Test_nginx_config (){
If $ DAEMON-t $ DAEMON_OPTS>/dev/null 2> & 1; then
Return 0
Else
$ DAEMON-t $ DAEMON_OPTS
Return $?
Fi
}
 
Case "$1" in
Start)
Echo-n "Starting $ DESC :"
Test_nginx_config
# Check if the ULIMIT is set in/etc/default/nginx
If [-n "$ ULIMIT"]; then
# Set the ulimits
Ulimit $ ULIMIT
Fi
Start-stop-daemon -- start -- quiet -- pidfile/var/run/$ NAME. pid \
-- Exec $ DAEMON -- $ DAEMON_OPTS | true
Echo "$ NAME ."
;;
 
Stop)
Echo-n "Stopping $ DESC :"
Start-stop-daemon -- stop -- quiet -- pidfile/var/run/$ NAME. pid \
-- Exec $ DAEMON | true
Echo "$ NAME ."
;;
 
Restart | force-reload)
Echo-n "Restarting $ DESC :"
Start-stop-daemon -- stop -- quiet -- pidfile \
/Var/run/$ NAME. pid -- exec $ DAEMON | true
Sleep 1
Test_nginx_config
# Check if the ULIMIT is set in/etc/default/nginx
If [-n "$ ULIMIT"]; then
# Set the ulimits
Ulimit $ ULIMIT
Fi
Start-stop-daemon -- start -- quiet -- pidfile \
/Var/run/$ NAME. pid -- exec $ DAEMON -- $ DAEMON_OPTS | true
Echo "$ NAME ."
;;
 
Reload)
Echo-n "Reloading $ DESC configuration :"
Test_nginx_config
Start-stop-daemon -- stop -- signal HUP -- quiet -- pidfile/var/run/$ NAME. pid \
-- Exec $ DAEMON | true
Echo "$ NAME ."
;;
 
Configtest | testconfig)
Echo-n "Testing $ DESC configuration :"
If test_nginx_config; then
Echo "$ NAME ."
Else
Exit $?
Fi
;;
 
Status)
Status_of_proc-p/var/run/$ NAME. pid "$ DAEMON" nginx & exit 0 | exit $?
;;
*)
Echo "Usage: $ NAME {start | stop | restart | reload | force-reload | status | configtest}"> & 2
Exit 1
;;
Esac
 
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 null.

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:

[Plain]
Root @ sloop2:/etc/init. d # pidof nginx
6639 6638 6637 6636 6635
Root @ sloop2:/etc/init. d # cat/var/run/nginx. pid
6635

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

[Plain]
Root @ sloop2:/etc/init. d # ps-def | grep nginx
Root 6635 1 0? 00:00:00 nginx: master process/usr/sbin/nginx
Www-data 6636 6635 0? 00:00:00 nginx: worker process
Www-data 6637 6635 0? 00:00:00 nginx: worker process
Www-data 6638 6635 0? 00:00:00 nginx: worker process
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.


 

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.