Configure Nginx in Linux environment

Linux——centos7 version

Installation environment configuration

  1. Nginx is written in C language, so you need to configure the C language compilation environment (to be connected to the Internet)

  2. Install the gcc environment

    [root@a ~]# yum install gcc-c++
    已加载插件:fastestmirror, langpacks
    Determining fastest mirrors
     * base: mirrors.aliyun.com
     * extras: mirrors.aliyun.com
     * updates: mirrors.aliyun.com
    base                   
    
  3. Solve the problems that occur when installing the gcc environment: Another app is currently holding the yum locak......
    the above problems occur because yum is in a locked state, and it is enough to force the yum process to be shut down

      rm -f /var/run/yum.pid     
    

Installing Nginx requires installing a third-party development package

Installing Nginx requires installing third-party development packages, which are required before compiling

  1. PCRE : The http module in nginx uses pcre to parse regular expressions, so the pcre library needs to be installed on linux

    [root@a ~]# yum install -y pcre pcre-devel
    已加载插件:fastestmirror, langpacks
    Loading mirror speeds from cached hostfile
     * base: mirrors.aliyun.com
     * extras: mirrors.aliyun.com
     * updates: mirrors.aliyun.com
     
    
  2. zlib : nginx uses zlib to gzio the contents of the http package, so this package needs to be installed

    [root@a ~]# yum install -y zlib zlib-devel
    已加载插件:fastestmirror, langpacks
    Loading mirror speeds from cached hostfile
     * base: mirrors.aliyun.com
     * extras: mirrors.aliyun.com
     * updates: mirrors.aliyun.com
    
  3. openssl : openssl is a powerful secure socket layer cipher library, nginx not only supports http protocol, but also supports https, so you need to install openssl library on linux

    [root@a ~]# yum install -y openssl openssl-devel
    已加载插件:fastestmirror, langpacks
    Loading mirror speeds from cached hostfile
     * base: mirrors.aliyun.com
     * extras: mirrors.aliyun.com
     * updates: mirrors.aliyun.com
    

Install Nginx

  1. Upload the Nginx source package to Linux

  2. Unzip Nginx:[root@a ~]# tar -xvf nginx-1.14.2.tar.gz

  3. Create a temporary directorymkdir /var/temp/nginx/client -p

  4. Execute the command configure to generate a Mikefile file

    ./configure \
    --prefix=/usr/local/nginx \
    --pid-path=/var/run/nginx/nginx.pid \
    --lock-path=/var/lock/nginx.lock \
    --error-log-path=/var/log/nginx/error.log \
    --http-log-path=/var/log/nginx/access.log \
    --with-http_gzip_static_module \
    --http-client-body-temp-path=/var/temp/nginx/client \
    --http-proxy-temp-path=/var/temp/nginx/proxy \
    --http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
    --http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
    --http-scgi-temp-path=/var/temp/nginx/scgi
    
  5. Execute the make command to compile:make

  6. Install Nginx:make install

Start and access Nginx

  1. Go to the nginx installation directory:

    [root@a nginx-1.14.2]# cd /usr/local/nginx/
    [root@a nginx]# ll
    总用量 4
    drwxr-xr-x. 2 root root 4096 1020 10:50 conf
    drwxr-xr-x. 2 root root   40 1020 08:02 html
    drwxr-xr-x. 2 root root    6 1020 14:57 logs
    drwxr-xr-x. 2 root root   36 1125 02:44 sbin
    [root@a nginx]# 
    
  2. Go to the sbin directory and execute the nginx command

    [root@a nginx]# cd sbin/
    [root@a sbin]# ll
    总用量 7472
    -rwxr-xr-x. 1 root root 3778520 1125 02:44 nginx
    -rwxr-xr-x. 1 root root 3870512 1020 08:02 nginx.old
    [root@a sbin]# 
    
    ./nginx 启动
    ./nginx -s stop 关闭
    ./nginx -s reload 重启
    ps aux | grep nginx 查看进程
    

Installed

  1. Open your client ip address, the following interface appears to indicate that the installation is completeinsert image description here

Guess you like

Origin blog.csdn.net/qq_43408367/article/details/128659241