1.官网下载包:nginx:下载
本人下的是:
编辑
2.安装要求的环境:
输入命令
yum -y install pcre pcre-devel zlib zlib-devel openssl openssl-devel
3.将nginx包上传到linux ,
我用的是Xftp7。具体步骤是什么远程连接上虚拟机后在左侧打开包的位置拖到右侧即可。
编辑
4.解压包
输入命令:tar -xzvf nginx-1.24.0.tar.gz /usr/local
5进入python文件夹生成脚本。
使用cofigure命令创建一个makeFile文件,执行下面的命令的时候,一定要进入到nginx-1.24.0目录里面去
编辑
后输入命令./configure \ 后将以下内容复制进去即可:
./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \--with-http_stub_status_module \--with-http_ssl_module \--with-file-aio \--with-http_realip_module \--with-http_v2_module \--with-pcre \--with-stream \ --with-stream_ssl_module \ --with-mail \--with-mail_ssl_module
注意:启动nginx之前,上边将临时文件目录指定为/var/temp/nginx,
6.需要在/var下创建temp及nginx目输入命令:
mkdir /var/temp/nginx -p后与安装python 一样进入nginx-1.14.0里面执行make命令进行编译后在执行make install 进行安装。
7.进入安装位置查看目录/etc/local/nginx
其中html是里面首页html文件。conf里面是配置文件。sbin里面只执行文件
8.启动nginx
执行命令: /etc/local/nginx/sbin后输入./nginx
9.查看nginx是否启动:输入 ps -aux | grep nginx
10.设置nginx开机自启动:
第一步:进入到/lib/systemd/system/目录
# cd /lib/systemd/system/
第二步:创建nginx.service文件,并编辑
# vim 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
[Unit]:服务的说明
Description:描述服务
After:描述服务类别
[Service]服务运行参数的设置
Type=forking是后台运行的形式
ExecStart为服务的具体运行命令
ExecReload为重启命令
ExecStop为停止命令
PrivateTmp=True表示给服务分配独立的临时空间
注意:[Service]的启动、重启、停止命令全部要求使用绝对路径
[Install]运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3
保存退出。
第三步:加入开机自启动
# systemctl enable nginx
如果不想开机自启动了,可以使用下面的命令取消开机自启动
# systemctl disable nginx
第四步:服务的启动/停止/刷新配置文件/查看状态
# systemctl start nginx.service 启动nginx服务
# systemctl stop nginx.service 停止服务
# systemctl restart nginx.service 重新启动服务
# systemctl list-units --type=service 查看所有已启动的服务
# systemctl status nginx.service 查看服务当前状态
# systemctl enable nginx.service 设置开机自启动
# systemctl disable nginx.service 停止开机自启动
后输入命令./configure \ 后将以下内容复制进去即可:
./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \--with-http_stub_status_module \--with-http_ssl_module \--with-file-aio \--with-http_realip_module \--with-http_v2_module \--with-pcre \--with-stream \ --with-stream_ssl_module \ --with-mail \--with-mail_ssl_module
注意:启动nginx之前,上边将临时文件目录指定为/var/temp/nginx,
6.需要在/var下创建temp及nginx目输入命令:
mkdir /var/temp/nginx -p后与安装python 一样进入nginx-1.14.0里面执行make命令进行编译后在执行make install 进行安装。
7.进入安装位置查看目录/etc/local/nginx
其中html是里面首页html文件。conf里面是配置文件。sbin里面只执行文件
8.启动nginx
执行命令: /etc/local/nginx/sbin后输入./nginx
9.查看nginx是否启动:输入 ps -aux | grep nginx
10.设置nginx开机自启动:
第一步:进入到/lib/systemd/system/目录
[root@iz2z init.d]# cd /lib/systemd/system/
第二步:创建nginx.service文件,并编辑
# vim 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
[Unit]:服务的说明
Description:描述服务
After:描述服务类别
[Service]服务运行参数的设置
Type=forking是后台运行的形式
ExecStart为服务的具体运行命令
ExecReload为重启命令
ExecStop为停止命令
PrivateTmp=True表示给服务分配独立的临时空间
注意:[Service]的启动、重启、停止命令全部要求使用绝对路径
[Install]运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3
保存退出。
第三步:加入开机自启动
# systemctl enable nginx
如果不想开机自启动了,可以使用下面的命令取消开机自启动
# systemctl disable nginx
第四步:服务的启动/停止/刷新配置文件/查看状态
# systemctl start nginx.service 启动nginx服务 # systemctl stop nginx.service 停止服务 # systemctl restart nginx.service 重新启动服务 # systemctl list-units --type=service 查看所有已启动的服务 # systemctl status nginx.service 查看服务当前状态 # systemctl enable nginx.service 设置开机自启动 # systemctl disable nginx.service 停止开机自启动