Nginx部署

Yum安装nginx

安装扩展源

1
yum -y install epel-release

安装nginx

1
yum -y install nginx

启动nginx

1
2
systemctl start nginx
systemctl enable nginx

编译安装nginx

下载nginx源码包

1
https://nginx.org/en/download.html

上传到服务器并解压

1
2
tar -zxvf nginx-1.24.0.tar
cd nginx-1.24.0

安装编译工具及依赖

1
yum install gcc openssl-devel zlib-devel pcre pcre-devel

编辑安装

1
2
3
4
5
./configure --prefix=/usr/local/nginx \
          --with-http_ssl_module \
          --with-http_v2_module \
          --with-http_gzip_static_module \
          --with-http_stub_status_module
1
make -j 6 && make install 

配置nginx启动文件

1
vim /usr/lib/systemd/system/nginx.service
1
2
3
4
5
6
7
8
9
10
11
12
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop

[Install]
WantedBy=multi-user.target

启动nginx

1
2
systemctl  start nginx
systemctl enable nginx

以下仅供内部部署使用

1
2
mkdir /usr/local/conf/nginx -p
mkdir /home/logs/nginx -p
1
vim /usr/local/nginx/conf/nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
user  root;
worker_processes 1;
error_log /home/logs/nginx/error.log;
error_log /home/logs/nginx/error.log notice;
error_log /home/logs/nginx/error.log info;
events {
  worker_connections 1024;
}

http {
  include       mime.types;
  default_type application/octet-stream;
  sendfile       on;
  keepalive_timeout 65;
  include /usr/local/conf/nginx/*.conf;
  access_log /home/logs/nginx/access.log;
}

重启nginx

1
2
3
systemctl  restart  nginx
###或者
/usr/local/nginx/sbin/nginx -s reload