Web集群架构-Nginx深入(一)

nginx原理

使用域名访问网站流程: DNS解析:域名 IP地址 连接80端口: tcp3次握手与网站的80端口建立连接 http请求豹纹:请求方法,URI,HOST等信息 GET /index.html HOST: cxk.oldboylinux.cn User-Agent: Chrome/xxx ngx处理: http请求,http区域处理 不同的server{} 区域(子配置文件)处理. 端口 域名:用户请求的域名与子配置文件server_name进行匹配. 匹配成功,就让对应的子配置文件(server{})处理 根据子配置文件的,root,location规则,index进行处理查找文件. 把找到的文件发回给用户. http响应豹纹: 状态码:200 ok server信息 其他信息 文件内容 客户收到文件内容,浏览器解析,进行展示

 虚拟主机

虚拟主机:相当于是1个网站,在ngx中通过server{}区域实现.

ngx中虚拟主机有不同的类型(配置不同)

 常见网站服务

nginx大部分使用nginx,Engine Xhttp: nginx.org/en/docs
Tengine基于Nginx二开,淘宝开源,更多内置模块
Openresty基于Nginx二开,加强Lua功能与模块

nginx部署测试项目了解结构

1.安装nginx,这里选择yum安装,生产环境没有网络,需自行下载nginx.tar,一般用源码安装,这里就不演示,下次讲

yum install nginx -y

2.检查nginx安装

rmp -ql | grep nginx

 

rpm -ql nginx

/bin/egrep
/bin/fgrep
/bin/grep
/etc/GREP_COLORS
/etc/profile.d/colorgrep.csh
/etc/profile.d/colorgrep.sh
/usr/libexec/grepconf.sh
/usr/share/doc/grep-2.20
/usr/share/doc/grep-2.20/ABOUT-NLS
/usr/share/doc/grep-2.20/AUTHORS
/usr/share/doc/grep-2.20/COPYING
/usr/share/doc/grep-2.20/ChangeLog
/usr/share/doc/grep-2.20/NEWS
/usr/share/doc/grep-2.20/README
/usr/share/doc/grep-2.20/THANKS
/usr/share/doc/grep-2.20/TODO
/usr/share/info/grep.info.gz
/usr/share/locale/af/LC_MESSAGES/grep.mo
/usr/share/locale/be/LC_MESSAGES/grep.mo
/usr/share/locale/bg/LC_MESSAGES/grep.mo
/usr/share/locale/ca/LC_MESSAGES/grep.mo
/usr/share/locale/cs/LC_MESSAGES/grep.mo
/usr/share/locale/da/LC_MESSAGES/grep.mo
/usr/share/locale/de/LC_MESSAGES/grep.mo
/usr/share/locale/el/LC_MESSAGES/grep.mo
/usr/share/locale/eo/LC_MESSAGES/grep.mo
/usr/share/locale/es/LC_MESSAGES/grep.mo
/usr/share/locale/et/LC_MESSAGES/grep.mo
/usr/share/locale/eu/LC_MESSAGES/grep.mo
/usr/share/locale/fi/LC_MESSAGES/grep.mo
/usr/share/locale/fr/LC_MESSAGES/grep.mo
/usr/share/locale/ga/LC_MESSAGES/grep.mo
/usr/share/locale/gl/LC_MESSAGES/grep.mo
/usr/share/locale/he/LC_MESSAGES/grep.mo
/usr/share/locale/hr/LC_MESSAGES/grep.mo
/usr/share/locale/hu/LC_MESSAGES/grep.mo
/usr/share/locale/id/LC_MESSAGES/grep.mo
/usr/share/locale/it/LC_MESSAGES/grep.mo
/usr/share/locale/ja/LC_MESSAGES/grep.mo
/usr/share/locale/ko/LC_MESSAGES/grep.mo
/usr/share/locale/ky/LC_MESSAGES/grep.mo
/usr/share/locale/lt/LC_MESSAGES/grep.mo
/usr/share/locale/nb/LC_MESSAGES/grep.mo
/usr/share/locale/nl/LC_MESSAGES/grep.mo
/usr/share/locale/pa/LC_MESSAGES/grep.mo
/usr/share/locale/pl/LC_MESSAGES/grep.mo
/usr/share/locale/pt/LC_MESSAGES/grep.mo
/usr/share/locale/pt_BR/LC_MESSAGES/grep.mo
/usr/share/locale/ro/LC_MESSAGES/grep.mo
/usr/share/locale/ru/LC_MESSAGES/grep.mo
/usr/share/locale/sk/LC_MESSAGES/grep.mo
/usr/share/locale/sl/LC_MESSAGES/grep.mo
/usr/share/locale/sr/LC_MESSAGES/grep.mo
/usr/share/locale/sv/LC_MESSAGES/grep.mo
/usr/share/locale/th/LC_MESSAGES/grep.mo
/usr/share/locale/tr/LC_MESSAGES/grep.mo
/usr/share/locale/uk/LC_MESSAGES/grep.mo
/usr/share/locale/vi/LC_MESSAGES/grep.mo
/usr/share/locale/zh_CN/LC_MESSAGES/grep.mo
/usr/share/locale/zh_TW/LC_MESSAGES/grep.mo
/usr/share/man/man1/egrep.1.gz
/usr/share/man/man1/fgrep.1.gz
/usr/share/man/man1/grep.1.gz
/etc/logrotate.d/nginx
/etc/nginx/fastcgi.conf
/etc/nginx/fastcgi.conf.default
/etc/nginx/fastcgi_params
/etc/nginx/fastcgi_params.default
/etc/nginx/koi-utf
/etc/nginx/koi-win
/etc/nginx/mime.types
/etc/nginx/mime.types.default
/etc/nginx/nginx.conf
/etc/nginx/nginx.conf.default
/etc/nginx/scgi_params
/etc/nginx/scgi_params.default
/etc/nginx/uwsgi_params
/etc/nginx/uwsgi_params.default
/etc/nginx/win-utf
/usr/bin/nginx-upgrade
/usr/lib/systemd/system/nginx.service
/usr/lib64/nginx/modules
/usr/sbin/nginx
/usr/share/doc/nginx-1.20.1
/usr/share/doc/nginx-1.20.1/CHANGES
/usr/share/doc/nginx-1.20.1/README
/usr/share/doc/nginx-1.20.1/README.dynamic
/usr/share/doc/nginx-1.20.1/UPGRADE-NOTES-1.6-to-1.10
/usr/share/licenses/nginx-1.20.1
/usr/share/licenses/nginx-1.20.1/LICENSE
/usr/share/man/man3/nginx.3pm.gz
/usr/share/man/man8/nginx-upgrade.8.gz
/usr/share/man/man8/nginx.8.gz
/usr/share/nginx/html/404.html
/usr/share/nginx/html/50x.html
/usr/share/nginx/html/en-US
/usr/share/nginx/html/icons
/usr/share/nginx/html/icons/poweredby.png
/usr/share/nginx/html/img
/usr/share/nginx/html/index.html
/usr/share/nginx/html/nginx-logo.png
/usr/share/nginx/html/poweredby.png
/usr/share/nginx/modules
/usr/share/vim/vimfiles/ftdetect/nginx.vim
/usr/share/vim/vimfiles/ftplugin/nginx.vim
/usr/share/vim/vimfiles/indent/nginx.vim
/usr/share/vim/vimfiles/syntax/nginx.vim
/var/lib/nginx
/var/lib/nginx/tmp
/var/log/nginx
/var/log/nginx/access.log
/var/log/nginx/error.log
 

 3.nginx目录结果

/etc/nginx/ nginx各种配的目录

/etc/nginx/nginx.conf主配置文件

/etc/nginx/conf.d/子配置文件(网站)

/etc/nginx/conf.d/default.conf默认的子配置文件

/usr/sbin/nginx ngx命令

usr/share/nginx/html/ ngx默认的站点目录,网站的根目录

/var/log/nginx/ ngx日志:访问日志,错误日志,跳转日志

/etc/logrotate.d/nginx日志切割(防止文件过大)

/etc/nginx/mime.types媒体类型

/etc/nginx/fastcgi_params ngx+php /etc/nginx/uwsgi_params ngx+python /usr/lib/systemd/system/nginx.service systemctl配置文件

/var/cache/nginx/缓存目录

 4.查看子文件 include /etc/nginx/default.d/*.conf;

include 文件包含,引用其他地方的ngx配置文件. user指定ngx用户. error_log错误日志 access_log 访问日志

 nginx必会的.conf文件编写语法

站中常用必会指令

listen 指定监听端口

server_name 指定域名

localtion 匹配请求中的uri

root 指定站点目录

index 指定站点首页文件

error_log 指定错误状态码

部署第一个CXK网站

网站要求说明
域名www.cxkblack.cn
站点目录/app/code/cxk
代码cxk.zip

 

1.修改子配置文件

 

2.检查nginx语法

nginx -t

 

3. 创建存放代码的目录

mkdir -p /app/code/cxk

4.上传代码

unzip /cxk.tar -d /app/code/cxk

5.关闭防火墙或写放行规则和selinux关闭

测试

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值