1.官网下载适用版本的nginx
nginx: downloadhttps://nginx.org/en/download.html2.分步安装nginx依赖的程序:
yum install gcc
yum install pcre-devel
yum install zlib zlib-devel
yum install openssl openssl-devel
3.解压nginx:
tar -zxvf nginx-1.22.1.tar.gz -C /usr/local(可指定自己的目录)
4.进入解压目录,开启ssl模块:
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_stub_status_module --with-http_ssl_module
5.编译并安装nginx:make && make install
6.添加用户和用户组:
/usr/sbin/groupadd -f www
/usr/sbin/useradd -g www www
7.nginx命令:
./sbin/nginx 启动nginx
./sbin/nginx -t 检查conf文件拼写
./sbin/nginx -c nginx.conf 指定配置文件启动
./sbin/nginx -s reload 重启
8.配置开机自启
创建nginx.service文件并将文件放置此目录 /lib/systemd/system/下;
文件内容:(nginx路径换成自己的目录即可)
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
systemctl daemon-reload #刷新配置
systemctl enable nginx #设置开机自启动
systemctl disable nginx #关闭开机自启动
配置完成后nginx命令如下:
systemctl start nginx.service #启动nginx
systemctl stop nginx.service #停止nginx