1、安装依赖
yum install -y bind-utils pcre pcre-devel make zlib zlib-devel gcc-c++ libtool openssl openssl-devel wget gcc gcc-c++ zip unzip tree vim telnet lrzsz net-tools yum-utils
2、下载解压
wget http://nginx.org/download/nginx-1.13.12.tar.gz
tar -zxvf nginx-1.13.12.tar.gz
3、编译安装
cd nginx-1.13.12/
./configure --prefix=/usr/local/nginx --with-http_ssl_module
make && make install
4、配置文件模板
[root@nginx_test conf]# more nginx.conf
#user nobody;
worker_processes 1;
worker_rlimit_nofile 65535;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
use epoll;
worker_connections 51200;
multi_accept on;
}
http {
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 512;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 50m;
#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;
include dooffe/*.conf;
}
# 多域名配置目录
mkdir /usr/local/nginx/conf/{dooffe,cert}
5、配置开机自启
vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx service
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable nginx
systemctl restart nginx
systemctl status nginx