Ubuntu configure Nginx and Nginx common commands

Download and install Nginx

1.1 install Nginx dependency Library


apt-get install build-essential
apt-get install libtool

yum installation is available under CentOS

The centos platform compilation environment uses the following instructions
 Install make:
yum -y install gcc automake autoconf libtool make

Install g + +:
yum install gcc gcc-c++  

1.2 install pcre dependency Library

sudo apt-get update
sudo apt-get install libpcre3 libpcre3-dev

1.3 install zlib dependency Library

apt-get install zlib1g-dev

1.4 install ssl dependency Library

apt-get install openssl

1.5 install Nginx

1.5.1 you can choose to download Nginx

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

1.5.2 decompress and configure edit

tar -zxvf nginx-1.11.3.tar.gz
#Enter directory
cd nginx-1.11.3
#To configure
./configure --prefix=/usr/local/nginx 

1.5.3 install Nginx

sudo make install

2. Configure nginx.conf

The program to be run can be placed in the html folder under the Nginx installation directory, or the access path can be configured in nginx.conf below

#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_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  65;

    #gzip  on;

    server {
        listen       8081;           #The port in the security group does not conflict with other programs
        server_name; #Server public ip

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        #The static page directory defaults to the html folder under Nginx, which can be configured as the absolute path of other directories
        root    /usr/local/nginx/html;
        #Default files under the root path on the home page
        index      index.html;

#        location / {
            #Cache settings on the user browser side
#           location ~* \.(css|js|jpg|jpeg|gif|png|swf|html|htm|json|xml|svg|woff|xsl|xslx|doc|docx|zip|rar)$ {
#               expires 1h;
#               if (-f $request_filename){
#                   break;
#               }
#           }
#           if (!-e $request_filename){
#               proxy_pass;
#           }
#        }
        #Custom missing page
        #error_page  404              /404.html;
        #Custom error page
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;

Three common commands

3.1 start up

# For example, / usr/local is the installation directory of Nginx

#The relative path is started and executed in the Nginx installation directory

3.2 stop

./sbin/nginx -s stop

./sbin/nginx -s quit

3.3 specify that conf under a path is the configuration file of Nginx

./sbin/nginx -c /usr/local/nginx/conf/nginx.conf

3.4 reload configuration file

./sbin/nginx -s reload

3.5 view Nginx process

ps -ef|grep nginx

3.6 kill process

# kill process number
kill -9 Process number

# Kill all nginx processes at once
sudo killall nginx

3.7 check whether it is occupied

netstat  -aon|findstr"80"

4. Common mistakes

4.1 PID loss

The error message is as follows:

[root@yoodb.com ~]# /usr/local/nginx/sbin/nginx -s reload 
nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory) 


a.  Nginx Under installation directory, find conf/nginx.conf.default Documents.
b.  Open file found #pid logs/nginx.pid;  Remove the leading#
c.  Return to sbin Under folder  cd ../sbin/
d.  ./nginx -c /Installation path/conf/nginx.conf.default  #Path for example / usr/local
e.  cd ../logs/ && ll  #Go back and check to see nginx.pid

4.2 start error

Error message: process already exists

Solution: Kill the process after checking ps -ef|grep nginx

4.3 editing

Error message:

pcre.h No such file or directory


#Install libpcre3
sudo apt-get install libpcre3-dev

Tags: Nginx sudo yum CentOS

Posted on Tue, 05 May 2020 16:00:45 -0400 by BinaryStar