现象:
nginx学习
方法:
一:下载
1:下载nginx:http://nginx.org/en/download.html
2:下载进行解压
3:进入window的cmd窗口,进入到nginx目录,使用“start nginx.exe ”进行安装
安装成功后,在“任务管理器”中会看到“nginx.exe”进程,
如果发现进程中并没有,那么说明你安装失败,你可以到你的D:\nginx-1.8.1目录下的logs文件夹下的error下查看,分析原因
二:设置
在浏览器地址栏输入:127.0.0.1,会进入到nginx的欢迎页面
start nginx.exe //开始
nginx.exe -s stop //停止nginx
nginx.exe -s reload //重新加载nginx 的配置文件
nginx.exe -s quit //退出nginx
三:配置文件
1:nginx的配置文件为解压目录下的conf
2:配置默认端口 为8088 listen标识监听占用8088端口
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8088;
server_name localhost;
}
}
3:配置一个虚拟主机 访问localhost:8001 将会跳转https://www.baidu.com
server {
listen 8001; #监听端口
server_name localhost; #域名可以有多个,用空格隔开
location / {
root html;
index index.html index.htm;
proxy_pass https://www.baidu.com;
}
}
4:配置多个
server {
listen 8001;
server_name localhost;
#localhost:8001 将转跳到这里
location / {
root html;
index index.html index.htm;
proxy_pass https://www.baidu.com;
}
#localhost:8001/worker 将转跳到这里
location /worker {
proxy_pass https://www.sougou.com/;
}
}