安装步骤
一、Window环境安装
1、官网下载nginx
网址:,企业管理系统定制开发下载稳定版本如 nginx-1.18.0.zip,企业管理系统定制开发下载后解压如下:
2、启动nginx
直接双击nginx.exe,企业管理系统定制开发双击后一个黑色的弹窗一闪而过。
3、检查是否启动成功
浏览器网址输入:http://localhost/,看到如下界面则表示启动成功:
二、Linux环境在线安装
安装nginx之前需要安装nginx所需要的依赖,pcre包和用以支持重写,正则以及网页压缩等等,OpenSSL是一个的包,应用程序可以使用这个包来进行安全通信,避免窃听,同时确认另一端连接者的身份。
1、安装pcre、zlib、
yum install pcre -yyum install pcre-devel -yyum install zlib -yyum install zlib-devel -yyum install openssl -yyum install openssl-devel -y
- 1
- 2
- 3
- 4
- 5
- 6
2、安装nginx
#解压cd /usr/localtar -zxvf nginx-1.16.0.tar.gz#进行configure配置,查看是否报错cd nginx-1.16.0/./configure#编译make#安装make install#在 /usr/local/nginx目录下,可以看到如下4个目录:#conf配置文件,html网页文件,logs日志文件,sbin主要二进制程序
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
PS:如果出现这个错误:./configure: error: C compiler cc is not found,则执行这个命令:
yum -y install gcc gcc-c++ autoconf automake make
- 1
3、启动nginx
#检查 nginx.conf 配置文件是否有错/usr/local/nginx/sbin/nginx -t#nginx启动命令:/usr/local/nginx/sbin/nginx#指定配置文件启动/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf#关闭命令:/usr/local/nginx/sbin/nginx -s stop#重启命令:/usr/local/nginx/sbin/nginx -s reload
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
三、Linux环境离线安装
1、安装pcre
tar -xvf pcre-8.43.tar.gzcd pcre-8.43./configure makemake install
- 1
- 2
- 3
- 4
- 5
2、安装openssl
tar -xvf openssl-1.0.2r.tar.gzcd openssl-1.0.2r./configmakemake install
- 1
- 2
- 3
- 4
- 5
3、安装zlib
tar -zxvf zlib-1.2.11.tar.gzcd zlib-1.2.11./configuremakemake install
- 1
- 2
- 3
- 4
- 5
4、安装nginx
tar -zxvf nginx-1.16.0.tar.gzcd nginx-1.16.0./configuremakemake install
- 1
- 2
- 3
- 4
- 5
5、启动nginx
/usr/local/nginx/sbin/nginx -t/usr/local/nginx/sbin/nginx
- 1
- 2
四、将nginx添加到服务器启动项中
1、配置
vi /etc/profile#在 profile文件最后一行添加配置: PATH=$PATH:/usr/local/nginx/sbin export PATH#刷新载入系统配置文件source /etc/profile
- 1
- 2
- 3
- 4
- 5
- 6
2、新增自定义一个 nginx.service 文件
vi /usr/lib/systemd/system/nginx.service
- 1
文件中添加如下内容:
[Unit]Description=nginxAfter=network.target[Service]Type=forkingExecStart=/usr/local/nginx/sbin/nginx# ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.confExecReload=/usr/local/nginx/sbin/nginx -s reloadExecStop=/usr/local/nginx/sbin/nginx -s stopPrivateTmp=true[Install]WantedBy=multi-user.target
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
PS: 注意上面的ExecStart/ExecReload/ExecStop 必须以自己的nginx安装路径为主。
自定义nginx.service 说明:
[Unit] #服务的说明Description #描述服务After #描述服务类别[Service] #服务运行参数的设置Type=forking #是后台运行的形式ExecStart #为服务的具体运行命令ExecReload #为重启命令ExecStop #为停止命令PrivateTmp=True #表示给服务分配独立的临时空间#注意:[Service]的启动、重启、停止命令全部要求使用绝对路径[Install] #运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
3、systemctl操作服务命令
systemctl start nginx.service #启动nginx服务systemctl stop nginx.service #停止nginx服务systemctl enable nginx.service #设置开机自启动systemctl disable nginx.service #停止开机自启动systemctl status nginx.service #查看服务当前状态systemctl restart nginx.service #重新启动服务systemctl list-units --type=service #查看所有已启动的服务
- 1
- 2
- 3
- 4
- 5
- 6
- 7
五、nginx及各依赖下载
1、nginx下载
下载地址:https://nginx.org/en/download.html
2、pcre下载
下载地址:http://www.pcre.org/
3、zlib下载
下载地址:http://www.zlib.net/