前言:
- 本实例信息:
部署系统: CentOS 8.0
部署要求:
数据盘挂载至 /media
Nginx 运行用户: www [UID、GID 皆是 501]
openresty 版本: 1.19.3.2
配置 Nginx 的日志切割
需要安装模块:
—with-http_ssl_module
—with-stream
—with-stream_ssl_module
—with-http_v2_module
运行用户: www, 运行用户组: www
备注:
Nginx 使用统一的主配置文件
openresty部署
1.创建 www用户, UID、GID 皆是 501,通过cat /etc/passwd,检查是否存在www用户
~]# groupadd -g 501 www
~]# useradd -u 501 -g www www
~]# cat /etc/passwd
2.下载相应版本
~]# wget https://openresty.org/download/openresty-1.19.3.2.tar.gz
3.解压到/usr/local/src
~]# tar -zxvf nginx-1.16.1.tar.gz -C /usr/local/src
4.安装依赖包,然后进入到目录进行编译安装
~]#yum install gcc gcc-c++ make automake autoconf libtool pcre* zlib openssl openssl-devel
~]# cd /usr/local/src//openresty-1.19.3.2
~]# ./configure --user=www --group=www --with-http_ssl_module --with-stream --with-stream_ssl_module --with-http_v2_module --with-luajit --with-http_realip_module --prefix=/usr/local/webserver/openresty
~]# make && make install
5.把nginx统一的主配置文件下载并覆盖好,覆盖之前尽量备份原配置文件,并根据主配置文件创建services、sites目录。
nginx.conf文件模板
user www;
worker_processes auto;
worker_rlimit_nofile 65535;
pid /usr/local/webserver/openresty/nginx/logs/nginx.pid;
events {
worker_connections 20480;
multi_accept on;
use epoll;
}
http {
server_tokens off;
# server_tag off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
include mime.types;
charset UTF-8;
proxy_ignore_client_abort on;
fastcgi_ignore_client_abort on;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for '
log_format access '$proxy_add_x_forwarded_for - $remote_user $remote_port [$time_local] $request '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" [ $request_body ] - "$request_time" - "$host"';
access_log off;
#access_log /media/raid10/logs/nginx/access.log;
#error_log /media/raid10/logs/nginx/error.log crit;
server_names_hash_bucket_size 128;
default_type application/octet-stream;
keepalive_timeout 60;
client_header_timeout 10;
client_body_timeout 10;
reset_timedout_connection on;
send_timeout 10;
client_body_buffer_size 4K;
client_header_buffer_size 16k;
client_max_body_size 8m;
large_client_header_buffers 4 64k;
gzip on;
gzip_comp_level 4;
gzip_disable "MSIE [1-6]\.";
gzip_proxied any;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_types text/plain application/javascript application/x-javascript application/json application/xml application/xml+rss text/javascript application/x-httpd-php text/css text/xml image/jpeg image/gif image/png;
gzip_vary on;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 60;
fastcgi_read_timeout 60;
fastcgi_buffer_size 32k;
fastcgi_buffers 8 64k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;
proxy_http_version 1.1;
proxy_connect_timeout 60;
proxy_read_timeout 60;
proxy_send_timeout 60;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
proxy_hide_header ETag;
proxy_hide_header X-Powered-By;
proxy_hide_header X-AspNet-Version;
proxy_set_header Connection "";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
open_file_cache max=102400 inactive=20s;
open_file_cache_min_uses 2;
open_file_cache_valid 30s;
open_file_cache_errors off;
include sites/*.conf;
include services/*.conf;
}
配置nginx文件
~]# vim nginx.conf (输入上面文件内容)
~]# mv /usr/local/webserver/openresty/nginx/conf/nginx.conf /usr/local/webserver/openresty/nginx/conf/nginx.conf.bak
~]# mv nginx.conf /usr/local/webserver/openresty/nginx/conf/nginx.conf
~]# cd /usr/local/webserver/openresty/nginx/conf/
~]# mkdir services
~]# mkdir sites
6.设置nginx环境变量,并加载环境变量
~]# vim /etc/profile.d/nginx.sh
export NGINX_HOME='/usr/local/webserver/nginx'
export PATH=$PATH:$NGINX_HOME/sbin
~]# . /etc/profile.d/nginx.sh
ps: . sh文件 可执行sh文件内容,相当于 sh sh文件
7.安装nfs-utils (此步骤如果木有磁盘共享需求可以不走)
~]# yum -y install nfs-utils
8.校验nginx,并根据报错创建缺少的目录
~]# nginx -t
~]# mkdir -p /media/backup/logs/nginx
~]# mkdir -p /media/raid10/logs/nginx
9.设置好nginx开机自启
~]# vim /etc/rc.d/rc.local
/usr/local/webserver/nginx/sbin/nginx
~]#chmod +x /etc/rc.d/rc.local