CentOS makes document server based on nginx


CentOS makes document server based on nginx

  1. Basic environment for installation

    yum install gcc-c++
    yum install -y pcre pcre-devel
    yum install -y zlib zlib-devel
    yum install -y openssl openssl-devel
  2. Find the latest stable version of nginx on the official website

    Stable version: https://nginx.org/download/nginx-1.18.0.tar.gz
    cd /home
    wget -c https://nginx.org/download/nginx-1.18.0.tar.gz
  3. Decompress compressed package data

    tar -zxvf nginx-1.18.0.tar.gz
    cd nginx-1.18.0
  4. Configure the service and compile the installation

    make install
    Find nginx configuration location
    whereis nginx
  5. Start stop nginx

    cd /usr/local/nginx/sbin/
    ./nginx -s stop
    ./nginx -s quit
    ./nginx -s reload
    Test whether nginx configuration is wrong
    ./nginx -t 
    Query nginx process:
    ps aux|grep nginx
  6. Set boot up

    vi /etc/rc.local
    #Add a line of code  
    #Set execution permission
    chmod 755 /etc/rc.local
  7. Configure document service

    server {
            listen       80;
            server_name  localhost;
            root /home/www/;
            #charset koi8-r;
            #access_log  logs/host.access.log  main;
            location / {
                autoindex on;             # Enable index function
                autoindex_ exact_ size off; #  Close the calculation of the exact size of the file (in bytes) and display only the approximate size (in KB, MB, GB)
                autoindex_ localtime on;   #  Display local time instead of GMT time
                charset utf-8; #  Avoid garbled Chinese
                #root   html;
                #index  index.html index.htm;
  8. Restart firewall settings and open port restrictions

    systemctl status firewalld
    systemctl start firewalld
    View all open ports
    firewall-cmd --list-port
    Permanent new port
    firewall-cmd --zone=public --add-port=80/tcp --permanent
    Permanently delete port
    firewall-cmd --zone=public --remove-port=80/tcp --permanent
    service iptables restart 
    firewall-cmd --reload
    Close firewall:
    Systemctl stop firewalld.service # stop firewall
    Systemctl disable firewalld.service # disable firewalld.service