Nginx 安装&使用
Nginx 安装&使用
1. 安装
1.1 下载
进入http://nginx.org/网站,下载nginx-1.17.5.tar.gz文件
1.2 安装
右键"解压到当前文件夹"即可, 安装目录不能包含中文
1.3 启动
双击 nginx.exe打开
注意: nginx启动以后没有任何反应,需要在任务管理器中查看进程
1.4 访问
打开浏览器, 输入访问路径 http://localhost/ ,进入如下页面:
2. 部署项目
2.1 Nginx 常用命令
执行命令前提:
1. 打开CMD命令窗口
2. 输入 D:
3. 进入nginx所在目录
cd D:\nginx-1.8.0 (咱们自己安装的目录)
4. 输入命令
常用命令
进入nginx安装目录后
停止服务器
nginx ‐s stop
重新加载配置
nginx ‐s reload
2.1 配置说明
为什么访问http://localhost/ ,进入到默认首页。
- 打开
nginx-1.8.0\conf\nginx.conf
配置文件
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80; #默认端口号
server_name localhost; #服务器IP地址
location / {
root html; # 默认项目
index index.html index.htm; #默认项目首页
}
error_page 500 502 503 504 /50x.html; # 项目报错以后跳转页面
location = /50x.html {
root html;
}
}
}
2.2 部署项目
① 复制项目到Nginx
将toutiao
放置到 nginx-1.8.0
目录下
② 修改配置文件
修改nginx-1.8.0\conf\nginx.conf
文件
server {
listen 80;
server_name localhost;
location / {
root toutiao; # 修改默认项目为: toutiao
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
③ 重启加载配置
1. 打开CMD命令窗口
2. 输入 D:
3. 进入nginx所在目录
cd D:\nginx-1.8.0
4. 重新加载配置
nginx -s reload
④ 访问测试
打开浏览器, 输入访问路径 http://localhost/ ,进入如下页面: