Linux云计算高端架构师:
- nginx服务器:
Nginx: 是一个高性能HTTP 和 反向代理 服务器、IMAP、POP3、SMTP 邮件代理服务器。
1.1特点: 高并发响应性能非常好,官方Nginx处理静态文件并发5w/s;负载均衡及反向代理性能非常强;可对后端服务进行健康检查;支持PHP cgi方式和FastCGI方式;可以作为缓存服务器、邮件代理服务器;支持热部署(在线升级)。
2.部署nginx:
yum部署:
配置仓库:vim /etc/yum.repos.d/nginx.repo
安装: yum install nginx -y
源码部署:
下载nginx源码包:wget http://nginx.org/download/nginx-1.18.0.tar.gz
解压: tar xf nginx-1.18.0.tar.gz
解决依赖: yum install pcre-devel zlib-devel -y
预编译: cd nginx-1.18.0
[root@node4 nginx-1.18.0]# ./configure --prefix=/usr/local/nginx
编译、安装: make && make install
启动服务: /usr/local/nginx/sbin/nginx
查看进程与端口: [root@node4 nginx]# ps -ef | grep nginx
- nginx常用指令:
[root@node4 nginx]# /usr/local/nginx/sbin/nginx -? nginx version: nginx/1.18.0
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p
prefix] [-g directives]
Options:
-?,-h : this help
显示nginx版本
-v : show version and exit
显示nginx版本以及nginx预编译参数
-V : show version and configure options then
exit
测试nginx配置文件语法问题
-t : test configuration and exit
测试nginx配置文件语法问题,并且还可以利用重定向进行配置文件备份
-T : test configuration, dump it and exit
静默模式启动nginx服务:
-q : suppress non-error messages during
configuration testing
给master进程发送信号,包括立即停止,优雅停止,重载日志文件,重载
配置文件。
-s signal : send signal to a master process: stop,
quit, reopen, reload
设置nginx主目录:
-p prefix : set prefix path (default:
/usr/local/nginx/)
设置nginx启动的配置文件
-c filename : set configuration file (default:
conf/nginx.conf)
设置nginx全局变量
-g directives : set global directives out of
configuration file
4. 配置nginx虚拟主机:
配置虚拟主机常见方式: 基于多域名配置虚拟主机; 基于多端口配置虚拟主机; 基于多IP配置虚拟主机;
基于多域名配置虚拟主机: vim /usr/local/nginx/conf/nginx.conf
…
keepalive_timeout 65;
include vhost/*.conf;
server {
listen 80;
server_name localhost;
…
mkdir -p /usr/local/nginx/conf/vhost
vim /usr/local/nginx/conf/vhost/www.jfedu.net.conf
server {
server_name www.jfedu.net;
root /usr/local/nginx/html/www;
location / {
index index.html;
}
}
vim /usr/local/nginx/conf/vhost/blog.jfedu.net.conf
server {
server_name blog.jfedu.net;
root /usr/local/nginx/html/blog;
location / {
index index.html;
}
}
创建目录: mkdir -p /usr/local/nginx/html/{www,blog}
创建测试页面: echo “this is www page” > /usr/local/nginx/html/www/index.html
echo “this is blog page” > /usr/local/nginx/html/blog/index.html
创建本地解析: echo “192.168.75.124 www.jfedu.net blog.jfedu.net” >
/etc/hosts
重启服务,访问测试: /usr/local/nginx/sbin/nginx -s reload
[root@node4 conf]# curl www.jfedu.net
this is www page
[root@node4 conf]# curl blog.jfedu.net
this is blog page