一、源码安装Nginx:
- 先安装gcc编译器(安装过的可以忽略)
[[email protected] ~]# yum -y install gcc gcc-c++ wget
- 进入src目录
[[email protected] ~]# cd /usr/local/src/
- 下载 nginx软件包
[[email protected] src]# wget http://nginx.org/download/nginx-1.14.0.tar.gz
- 解压
[[email protected] src]# tar -zxvf nginx-1.14.0.tar.gz
- 进入nginx-1.14.0目录
[[email protected] src]# cd nginx-1.14.0/
- 安装依赖
[[email protected] nginx-1.14.0]# yum -y install openssl openssl-devel
- ./configure软件配置与检查
[[email protected]]#./configure--prefix=/usr/local/nginx --with-http_ssl_module
- 安装
[[email protected] nginx-1.14.0]# make [[email protected] nginx-1.14.0]# make install
- 启动nginx
[[email protected] nginx-1.14.0]#cd /usr/local/nginx/sbin [[email protected] nginx-1.14.0]#./nginx
查看是否启动成功
[[email protected] nginx-1.14.0]# ps aux |grep nginx
二、systemctl管理:
- 创建配置文件
源码安装的nginx在/etc/systemd/system/multi-user.target.wants/目录下是没有nginx.service这个文件的,所以要新建[[email protected] nginx-1.14.0]#vim /usr/lib/systemd/system/nginx.service
- 写入内容(全部复制进去,然后修改)
[Unit] Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/ After=network-online.target remote-fs.target nss-lookup.target Wants=network-online.target [Service] Type=forking PIDFile=/var/run/nginx.pid ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s TERM $MAINPID [Install] WantedBy=multi-user.target
- 修改 [Service]内容
将: ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf, 改为: ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
- 设置开机启动
[[email protected] nginx-1.14.0]# systemctl enable nginx.service
- 关闭之前启动的nginx服务
[[email protected] nginx-1.14.0]# pkill -9 nginx
- 重载修改过的所有配置文件
[[email protected] nginx-1.14.0]#systemctl daemon-reload
- 重新启动nginx服务
[[email protected] nginx-1.14.0]#systemctl start nginx
最后可以用浏览器访问自己虚拟机的IP:192.168.xxx.xx
原文地址:https://www.cnblogs.com/None-zreo-0/p/9609439.html
时间: 2024-10-10 19:04:48