DataLife Engine / Установка веб сервера NGINX в CentOS 8 / RHEL 8

Установка веб сервера NGINX в CentOS 8 / RHEL 8


NGINX — это один из самых популярных в мире веб-серверов, который обеспечивает работу крупнейших сайтов в Интернете с огромным трафиком. Обычно он использует ресурсы эффективнее, чем Apache, и может использоваться как веб-сервер для статического контента или как обратный прокси-сервер.

#!/bin/bash

echo "Update the package lists..."
dnf check-update

echo "Install the prerequisites..."
dnf install dnf-utils -y

echo "Adding nginx official repos..."
cat <<'EOT' > /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
EOT

echo "Install nginx stable release from official repo..."
dnf install nginx -y

echo "Renaming nginx.conf to nginx.conf.bak"
mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak

echo "Creating new nginx.conf..."
cat <<'EOT' > /etc/nginx/nginx.conf
user  nginx;
worker_processes  auto;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections 1024;
    use epoll;
    multi_accept on;
}


http {
    include       /etc/nginx/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  /var/log/nginx/access.log  main;

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    server_names_hash_bucket_size 64;
    server_tokens off;
    #gzip  on;

    server {
        listen       0.0.0.0:80 default_server;
        server_name  localhost;
        root	     /usr/share/nginx/html;

        location / {
            deny all;
        }

        error_page 404 /404.html;
    	    location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
    	    location = /50x.html {
        }
    }    

    include /etc/nginx/conf.d/*.conf;
}
EOT

echo "Enable and start nginx.service"
systemctl enable --now nginx

echo "Opening http and https ports..."
firewall-cmd --zone=public --add-port=80/tcp
firewall-cmd --zone=public --add-port=443/tcp
firewall-cmd --runtime-to-permanent
firewall-cmd --reload

nginx-rhel-setup.sh [2.16 Kb] (cкачиваний: 42)
27-07-2020, 13:47
Вернуться назад