Nginx Installation Summary

Source: Internet
Author: User
Tags epoll mkdir openssl library sendfile nginx server
Nginx Installation Summary 1. Nginx Installation

First you need to install gcc-g++, PCRE, and zlib beforehand. Pcre used to override Rewrite,zlib for gzip compression

To the installation directory,
Download Nginx

wget http://nginx.org/download/nginx-1.5.9.tar.gz

Extract

TAR-ZXVF nginx-1.5.9.tar.gz

Go to the new directory

CD nginx-1.5.9
installation configuration for Nginx

Make installation configuration Configure
After the Configure command, add the corresponding configuration entry:

–prefix=path defines a directory that holds the files on the server, which is the Nginx installation directory. /usr/local/nginx is used by default.

–prefix=path defines a directory that holds the files on the server, which is the Nginx installation directory. /usr/local/nginx is used by default. –sbin-path=path sets the path of the Nginx executable file, which defaults to Prefix/sbin/nginx. –conf-path=path set the path to the nginx.conf configuration file. Nginx allows you to start with a different configuration file, using the-C option on the command line. Default is prefix/conf/nginx.conf. –pid-path=path sets the Nginx.pid file, the process number of the main process that will be stored. After the installation is complete, you can change the file name at any time, using the PID directive in the nginx.conf configuration file. By default, the file name is Prefix/logs/nginx.pid. –error-log-path=path sets the name of the main error, warning, and diagnostic file. After the installation is complete, you can change the file name at any time, using the Error_log directive in the nginx.conf configuration file. By default, the file name is Prefix/logs/error.log. –http-log-path=path the name of the log file for the HTTP server on which the master request is set. After the installation is complete, you can change the file name at any time, using the Access_log directive in the nginx.conf configuration file. By default, the file name is Prefix/logs/access.log. –user=name the user who set up the Nginx worker process. The user directive used in the Nginx.conf configuration file can be changed at any time after the installation is complete. The default user name is nobody. –group=name sets the user group for the Nginx worker process. The user directive used in the Nginx.conf configuration file can be changed at any time after the installation is complete. The default is not a privileged user. –with-select_module–without-select_module enables or disables building a module to allow the server to use the Select () method. The module will be automatically built if the platform does not support Kqueue,epoll,rtsig or/dev/poll. –with-poll_module–without-poll_module enables or disables building a module to allow the server to use the poll () method. The module will be automatically built if the platform does not support Kqueue,epoll,rtsig or/dev/poll. –without-http_gzip_module-a response module that does not compile a compressed HTTP server. Compiling and running this module requires a zlib library. –without-http_rewrite_module does not compile the rewrite module. Compiling and running this module requires PCRE library support. –without-http_proxy_module-does not compile Http_proxy modules. –with-http_ssl_module-uses the HTTPS protocol module. By default, the module is not built. It is necessary to establish and run the OpenSSL library for this module. –with-pcre=path-set the source path for the Pcre library. The source code (version 4.4-8.30) of the Pcre library needs to be downloaded and decompressed from the Pcre website. The rest of the work is nginx./configure and make to complete. Regular expressions are used in location directives and ngx_http_rewrite_module modules. –with-pcre-jit-compilation Pcre contains "Just-in-time compilation" (1.1.12, Pcre_jit directives).

–with-zlib=path-set the source path for the zlib library. To download from zlib (version 1.1.3-
1.2.5) and decompression. The rest of the work is nginx./configure and make complete. The Ngx_http_gzip_module module requires the use of zlib.

–with-cc-opt=parameters-setting additional parameters will be added to the cflags variable. For example, when you use a pcre library on a FreeBSD, you need to use: –with-cc-opt= "-i/usr/local/include ... if you need to increase the number of files supported by select (): –with-cc-opt="-D fd_ setsize=2048 ".

–with-ld-opt=parameters-sets the additional parameters that will be used during the link. For example, when using the Pcre Library of the system under FreeBSD, you should specify: –with-ld-opt= "-l/usr/local/lib".

For example

./configure--sbin-path=/usr/local/nginx/nginx \
--conf-path=/usr/local/nginx/nginx.conf \
--pid-path=/ usr/local/nginx/nginx.pid \
--without-http_rewrite_module \
--without-http_gzip_module \
--user=nginx \
--group=nginx  

(here because I did not install Pcre, zlib, so the election is without)

After success, you can see that the makefile file appears in the directory.
Use make and make install successively, install completes.

You can use Nginx–v to view the version number. 2. Start and stop of Nginx

Startup code:
Format: Nginx installation directory address-C nginx configuration file address
such as:/usr/sbin/nginx-c/root/zhangxiao/nginx-1.5.9/conf/nginx.conf

To view a process:

Ps-ef|grep Nginx

To stop a process:

Kill-quit Process Number
nginx.conf configuration file for Nginx

The default generated files are:

#user nobody;

Worker_processes 1;
#error_log Logs/error.log;
#error_log Logs/error.log Notice;

#error_log Logs/error.log Info;


#pid Logs/nginx.pid;


Events {worker_connections 1024;}
    HTTP {include mime.types;

    Default_type Application/octet-stream; #log_format Main ' $remote _addr-$remote _user [$time _local] "$request" ' # ' $status $body _bytes_sen

    T "$http _referer" "$http _user_agent" "$http _x_forwarded_for";

    #access_log Logs/access.log Main;
    Sendfile on;

    #tcp_nopush on;
    #keepalive_timeout 0;

    Keepalive_timeout 65;

    #gzip on;
        server {Listen 80;

        server_name localhost;

        #charset Koi8-r;

        #access_log Logs/host.access.log Main;
            Location/{root HTML;
        Index index.html index.htm;

        } #error_page 404/404.html; # REDIRECT Server error pages To the static page/50x.html # Error_page 502 503 504/50x.html;
        Location =/50x.html {root html;    # Proxy The PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ {#
        Proxy_pass http://127.0.0.1;
        # Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ {
        # root HTML;
        # Fastcgi_pass 127.0.0.1:9000;
        # Fastcgi_index index.php;
        # Fastcgi_param Script_filename/scripts$fastcgi_script_name;
        # include Fastcgi_params;
        #} # Deny access to. htaccess files, if Apache ' s document Root # concurs with Nginx ' s one #
        #location ~/\.ht {# deny all; #}} # Another virtual host using mix of ip-, name-, and port-based configuration # #server {# l
    Isten 8000;# Listen somename:8080;

    # server_name somename alias Another.alias;
    # location/{# root HTML;
    # index index.html index.htm;
    #} # HTTPS Server # #server {# listen 443 SSL;

    # server_name localhost;
    # ssl_certificate Cert.pem;

    # Ssl_certificate_key Cert.key;
    # Ssl_session_cache shared:ssl:1m;

    # ssl_session_timeout 5m; # ssl_ciphers high:!anull:!
    MD5;

    # ssl_prefer_server_ciphers on;
    # location/{# root HTML;
    # index index.html index.htm;
 #    }
    #}

}

File structure:

...              #全局块

Events {         #events块
   ...
}

HTTP      #http块
{
    ...   #http全局块
    Server        #server块
    { 
        ...       #server全局块
        location [pattern]   #location块
        {
            ...
        }
        Location [pattern] 
        {
            ...
        }
    } Server
    {
      ...
    }
    ...     #http全局块
}

which

1, the global block: Configuration affects Nginx global directives. Generally have run Nginx Server user group, nginx process PID store path, log storage path, configuration file Introduction, allow the generation of worker
Number of process.
2, events block: Configuration affects the Nginx server or network connection with the user. With the maximum number of connections per process, choose which event-driven model to handle the connection request, whether to accept multiple network connections at the same time, and enable multiple networking serialization.
3, HTTP BLOCK: You can nest multiple servers, configure agents, caching, log definitions and other most functions and Third-party module configuration. such as file introduction, Mime-type definition, log customization, whether to use Sendfile transmission files, connection timeout, the number of single connection requests.
4, server block: Configure the relevant parameters of the virtual host, one HTTP can have more than one server.
5, location block: Configure the requested routing, as well as the processing of various pages. Nginx Exception Resolution start Nginx Error:

Nginx: [Emerg] Getpwnam ("Nginx") failed In/usr/local/nginx/conf/nginx.conf:2

Because the startup account used in the configuration file is not found in the system
Solution:

USERADD-G groupname username
start Nginx Error:

Starting Nginx:nginx: [Emerg] mkdir () "/var/tmp/nginx/client/" failed
(2:no such file or directory)

Insufficient permissions to resolve:

cd/var/tmp/
mkdir-p/var/tmp/nginx/{client,proxy,fastcgi,uwsgi,scgi}

Reference:http://www.cnblogs.com/knowledgesea/p/5175711.html http://blog.csdn.net/a2796749/article/details/ 50492664 http://blog.csdn.net/tjcyjd/article/details/50695922

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.