Nginx版本及目录配置
Nginx的衍生版本
- nginx开源版
- nginx pluss商业版:f5收购之后开发的商业版
- openResty:通过lua扩展nginx实现可扩展的web平台(国产)
- tengine:在nginx之上做了二次开发(淘宝)
openresty
内置动态脚本语言lua,使用lua可以访问mysql(较少使用),连接kafka(使用较多),连接redis,发http 请求集成微服务(注册到eureka等注册中心,作为服务)。
搭建nginx
查看download
nginx的目录结构
- conf:配置文件
- html:网站默认根目录
- index.html:默认静态网页
- logs:存放所有日志的位置
- sbin:可执行文件
启动命令
cd /usr/local/nginx/sbin/
./nginx //启动
./nginx -s stop //此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程。
./nginx -s quit //此方式停止步骤是待nginx进程处理任务完毕进行停止
./nginx -s reload //重启
创建服务
或者将nginx配置成服务,开机启动
systemctl reload nginx.server 重新加载配置
systemctl status nginx.server -l 查看错误信息。排查错误
配置文件
conf下的nginx.conf
其中的server代表一台主机
配置了server_name就可以根据request中header的host匹配
server{
listen:80;//该主机监听的端口号
server_name:liuzhongyang1.com;//主机的域名,localhost是匹配找不到
location / {
# root:html;
root:/html/liuzhongyang1;//当前根目录
index:index.html index.htm;//默认访问的首页
}
}
server{
listen:80;
server_name:liuzhongyang2.com;
location / {
root:/html/liuzhongyang2
index:index.html index.htm;
}
}