一、Windows系统操作如下

1、下载

官方网站:https://nginx.org/en/download.html

image

2、安装

1、下载后解压(切记不能含有中文路径!!),文件结构如图

image
2、启动
两种方法:
1) 直接双击该目录下的"nginx.exe",即可启动nginx服务器;
2) 命令行进入该文件夹,执行start nginx命令,也会直接启动nginx服务器。
3、验证
开浏览器,输入地址:http://localhost,访问页面,出现如下页面表示访问成功。

image
4、Nginx Windows基本操作指令
启动服务:start nginx
退出服务:nginx -s quit
强制关闭服务:nginx -s stop
重载服务:nginx -s reload  (重载服务配置文件,类似于重启,服务不会中止)
验证配置文件:nginx -t
使用配置文件:nginx -c "配置文件路径"
使用帮助:nginx -h
重启Nginx:nginx -s reopen

二、Linux系统操作如下

1、下载安装依赖包

1、模块依赖性Nginx需要依赖下面3个包

  • ssl功能需要 openssl 库( 点击下载 )——nginx搭建加密站点https
  • gzip模块需要 zlib 库(点击下载)——nginx的静态资源压缩功能
  • rewrite模块需要 pcre 库(点击下载)——nginx需要支持url重写
    依赖包安装顺序依次为:openssl、zlib、pcre, 最后安装Nginx包。

可以按照上边逐个下载,我这边将其一起下载(为了省事,偷懒O(∩_∩)O)

# 安装编译工具及库文件
[root@localhost src]# yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel

PCRE 作用是让 Nginx 支持 Rewrite 功能。

下载 PCRE 安装包,下载地址: http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz

[root@localhost src]# cd /usr/local/src/
[root@localhost src]# wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz

2、解压安装包

[root@localhost src]# tar zxvf pcre-8.35.tar.gz

3、进入安装包目录

[root@localhost src]# cd pcre-8.35

4、编译安装

[root@localhost pcre-8.35]# ./configure
[root@localhost pcre-8.35]# make && make install

5、查看pcre版本

[root@localhost pcre-8.35]# pcre-config --version

image

2、下载安装Nginx

1、下载 Nginx,下载地址:https://nginx.org/en/download.html

[root@localhost src]# cd /usr/local/src/
[root@localhost src]# wget http://nginx.org/download/nginx-1.6.2.tar.gz

2、解压安装包

[root@localhost src]# tar zxvf nginx-1.6.2.tar.gz

3、进入安装包目录

[root@localhost src]# cd nginx-1.6.2

4、编译安装

[root@localhost nginx-1.6.2]# ./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35
[root@localhost nginx-1.6.2]# make
[root@localhost nginx-1.6.2]# make install

5、查看nginx版本

[root@localhost nginx-1.6.2]# /usr/local/webserver/nginx/sbin/nginx -v

image

6、启动服务

#查询安装路径
whereis nginx

#进入文件路径内
cd /usr/local/webserver/nginx/sbin

#启动服务
./nginx

3、验证以及环境变量的添加

此时也可以为Nginx添加环境变量,以便操作服务【自由选择、非必要操作】。(如何添加Linux环境变量?)

(1)检测是否安装成功:
image

(2)查看nginx 的状态 ps -ef | grep nginx 出现master 则启动成功
image

关闭nginx 命令 kill -9 8725(进程号 上面的) 则关闭nginx

停止 nginx 命令: ./nginx -s stop

重启nginx命令:./nginx -s reload

(3)或者,在浏览器地址输入"127.0.0.1"回车出现如下页面,则表示安装成功。
curl -L 127.0.0.1

image

posted on 2021-06-08 11:33  史振兴  阅读(181)  评论(0编辑  收藏  举报