CentOS 7 Source Installation Nginx

Posted by jmgarde on Wed, 31 Jul 2019 10:08:18 +0200

System Platform: Tencent Cloud Server CentOS 7.3 64 bits

Installation of compiler tools and library files

[root@VM_0_5_centos ~]# yum install -y make zlib zlib-devel gcc-c++ libtool openssl openssl-devel

Installation of pcre

The function of PCR E is to enable Nginx to support Rewrite function.

1. Download the PCR E package
[root@VM_0_5_centos ~]# cd /usr/local/src/
[root@VM_0_5_centos src]# wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
2. Decompression installation package

[root@VM_0_5_centos src]# tar zxvf pcre-8.35.tar.gz

3. Enter the installation package directory after decompression

[root@VM_0_5_centos src]# cd pcre-8.35

4. Compile and Install
[root@VM_0_5_centos pcre-8.35]# ./configure
[root@VM_0_5_centos pcre-8.35]# make
[root@VM_0_5_centos pcre-8.35]# make install
5. View the pcre version
[root@VM_0_5_centos pcre-8.35]# pcre-config --version
8.35

III. Installation of Nginx

1. Download Nginx
[root@VM_0_5_centos ~]# cd /usr/local/src/
[root@VM_0_5_centos src]# wget http://nginx.org/download/nginx-1.16.0.tar.gz
2. Decompression installation package

[root@VM_0_5_centos src]# tar zxvf nginx-1.16.0.tar.gz

3. Enter the decompressed directory

[root@VM_0_5_centos src]# cd nginx-1.16.0

4. Compile and Install
[root@VM_0_5_centos nginx-1.16.0]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35
[root@VM_0_5_centos nginx-1.16.0]# make
[root@VM_0_5_centos nginx-1.16.0]# make install

- prefix specifies the installation path

5. View nginx version
[root@VM_0_5_centos nginx-1.16.0]# /usr/local/nginx/sbin/nginx -v
nginx version: nginx/1.16.0

IV. Nginx Configuration

User www for creating Nginx runtime

[root@VM_0_5_centos ~]# groupadd www
[root@VM_0_5_centos ~]# useradd -g www www

Modify configuration files

[root@VM_0_5_centos ~]# vim /usr/local/nginx/conf/nginx.conf

user  www www; #Specify user and group names
worker_processes  1; #Settings are consistent with the number of cpu cores

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_sent "$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  60;

    #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   500 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 {
    #    listen       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;
    #    }
    #}

}

Follow-up configuration according to needs;

Check the correctness command of configuration file nginx.conf:

[root@VM_0_5_centos conf]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

V. Start Nginx

[root@VM_0_5_centos conf]# /usr/local/nginx/sbin/nginx

6. Nginx other search commands

[root@VM_0_5_centos conf]# /usr/local/nginx/sbin/nginx -s reload   #Reload configuration file
[root@VM_0_5_centos conf]# /usr/local/nginx/sbin/nginx -s reopen   #Restart Nginx
[root@VM_0_5_centos conf]# /usr/local/nginx/sbin/nginx -s stop     #Stop nginx     

Topics: PHP Nginx zlib OpenSSL