1、安装Nginx

Windows安装方式:

  • 1)到官网下载对应操作系统的版本
  • 2)把下载的压缩包解压
  • 3)windows下双击nginx.exe
  • 4)浏览器输入localhost会出现欢迎页面表示成功

Linux安装方式:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#安装编译工具及库文件
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel

#下载PCRE
curl -O https://nchc.dl.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz

#解压PREC
tar -zxvf pcre-8.35.tar.gz

#进入到目录中
cd pcre-8.35

#进行编译安装
./configure
make && make install

#查看prec版本号
pcre-config --version

#下载nginx
curl -O http://nginx.org/download/nginx-1.18.0.tar.gz

#解压
tar -xzvf nginx-1.18.0.tar.gz

#切换到nginx目录
cd nginx-1.18.0

#配置文件
./configure --prefix=/opt/nginx --with-http_stub_status_module --with-http_ssl_module

#编译安装
make && make install

#查看nginx版本号
nginx -v

2、常用命令

  • 1)启动服务:start nginx
  • 2)退出服务:nginx -s quit
  • 3)强制关闭服务:nginx -s stop
  • 4)重载服务:nginx -s reload  (重载服务配置文件,类似于重启,服务不会中止)
  • 5)验证配置文件:nginx -t
  • 6)使用配置文件:nginx -c “配置文件路径”
  • 7)使用帮助:nginx -h

3、配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
server {
listen 80;#监听80端口
server_name localhost; #监听这个域名

#charset koi8-r;

#access_log logs/host.access.log main;#访问日志写入到文件中

location / {
root html;#网站路径
index index.html index.htm; #默认页面设置
}
}