yum -y install gcc gcc-c++ autoconf pcre pcre-devel make automake
yum -y install wget httpd-tools vim
cd /opt;mkdir app download logs work backup
分别为源码目录,下载的软件包目录,自定义目录、shell脚本,默认配置文件的备份等
1确认网络可用 ping www.baidu.com
2确认yum源可用 yum list | grep gcc
3确认关闭iptables规则
查看 iptables -L
如果有,关闭 iptables -F
iptables -t nat -L
iptables -t nat -F
4确认停用selinux
查看是否启用 getenforce
关闭 setenforce 0
查看SELinux状态:
1、/usr/sbin/sestatus -v ##如果SELinux status参数为enabled即为开启状态
SELinux status: enabled
2、getenforce ##也可以用这个命令检查
关闭SELinux:
1、临时关闭(不用重启机器):
setenforce 0 ##设置SELinux 成为permissive模式
##setenforce 1 设置SELinux 成为enforcing模式
2、修改配置文件需要重启机器:
修改/etc/selinux/config 文件
将SELINUX=enforcing改为SELINUX=disabled
重启机器即可
http://mirrors.163.com/centos/7.6.1810/isos/x86_64/
http://nginx.org/
Nginx (engine x) 是一个高性能的HTTP和反向代理web服务器,同时也提供了IMAP/POP3/SMTP服务
Nginx 是一个开源且高性能、可靠的的http中间件、代理服务
中间件是在操作系统功能范围外为应用提供服务的多用途软件。任何位于内核和用户应用之间的软件都可以是中间件。中间件不提供传统应用的功能,而是将软件与其他软件衔接。由于中间件能够让数据从一个应用流动到另一个中,因此把它比作输水管最为贴切。
中间件就是程序中可织入的,可重用的,与业务逻辑无关的各种组件。
中间件(middleware)是基础软件的一大类,属于可复用软件的范畴。
顾名思义,中间件处于操作系统软件与用户的应用软件的中间。
中间件在操作系统、网络和数据库之上, 应用软件的下层,总的作用是为处于自己上层的应用软件提供运行与开发的环境,帮助用户灵活、高效地开发和集成复杂的应用软件。
在众多关于中间件的定义中,比较普遍被接受的是 IDC 表述的:中间件是一种独立的系统软件或服务程序,分布式应用软件借助这种软件在不同的技术之间共享资源,中间件位于客户机服务器的操作系统之上,管理计算资源和网络通信。
分类:数据访问中间件,远程调用中间件,消息中间件,交易中间件,对象中间件。
二 常见的http中间件服务
httpd apache
iis 微软
gws 谷歌
nginx
三 nginx优点
1 io多路复用epoll
二、 什么是epoll
io多路复用的实现方式select、poll、epoll 未完
2 轻量级
功能模块少
代码模块化–易于开发人员的二次开发 Tengine https://tengine.taobao.org/
Tengine是由淘宝网发起的Web服务器项目。它在Nginx的基础上,针对大访问量网站的需求,添加了很多高级功能和特性。Tengine的性能和稳定性已经在大型的网站如淘宝网,天猫商城等得到了很好的检验。它的最终目标是打造一个高效、稳定、安全、易用的Web平台。
3 cpu亲和 (affinity)
4 sendfile
安装
http://nginx.org/en/download.html
Mainline version 开发版
changes 版本更新的改变
pgb 包安全校验-第三方网站下载的需要安全校验
Stable version 稳定版
Legacy version 历史版本
Source Code 源代码
Pre-Built Packages 基于yum方式安装
我使用此方式安装
http://nginx.org/en/linux_packages.html
按官方指导
添加yum源
cd /etc/yum.repos.d/
cat CentOS-Base.repo
[base]
name=CentOS-
r
e
l
e
a
s
e
v
e
r
−
B
a
s
e
m
i
r
r
o
r
l
i
s
t
=
h
t
t
p
:
/
/
m
i
r
r
o
r
l
i
s
t
.
c
e
n
t
o
s
.
o
r
g
/
?
r
e
l
e
a
s
e
=
releasever - Base mirrorlist=http://mirrorlist.centos.org/?release=
releasever−Basemirrorlist=http://mirrorlist.centos.org/?release=releasever&arch=KaTeX parse error: Expected 'EOF', got '&' at position 9: basearch&̲repo=os&infra=infra
#baseurl=http://mirror.centos.org/centos/
r
e
l
e
a
s
e
v
e
r
/
o
s
/
releasever/os/
releasever/os/basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
vim /etc/yum.repos.d/nginx.repo
拷贝
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/
r
e
l
e
a
s
e
v
e
r
/
releasever/
releasever/basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/
r
e
l
e
a
s
e
v
e
r
/
releasever/
releasever/basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
保存
注意 确认 baseurl和以前的yum源的路径后缀相同 /centos/
r
e
l
e
a
s
e
v
e
r
/
releasever/
releasever/basearch/
验证
yum list | grep nginx
安装
yum install nginx
验证
nginx -v 版本
nginx -V 编译参数
二 基本参数使用
安装目录
rpm -ql nginx 查看安装目录
[root@rain yum.repos.d]# rpm -ql nginx
遵循linux的文件规范 etc下放核心配置
/etc/logrotate.d/nginx nginx日志轮转 用于logrotate服务日志的切割
/etc/nginx
/etc/nginx/nginx.conf
/etc/nginx/conf.d
/etc/nginx/conf.d/default.conf 这三个为启动时需要加载的配置文件
/etc/nginx/fastcgi_params
/etc/nginx/uwsgi_params
/etc/nginx/scgi_params 这三个 cgi相关配置 fastcgi配置
/etc/nginx/koi-utf
/etc/nginx/koi-win
/etc/nginx/win-utf 编码转换的映射文件
/etc/nginx/mime.types http协议的content-type与扩展名的对应关系
/etc/sysconfig/nginx
/etc/sysconfig/nginx-debug
/usr/lib/systemd/system/nginx-debug.service
/usr/lib/systemd/system/nginx.service 用于配置系统守护进程管理器管理方式
/usr/lib64/nginx
/usr/lib64/nginx/modules
/etc/nginx/modules nginx模块目录
/usr/libexec/initscripts/legacy-actions/nginx
/usr/libexec/initscripts/legacy-actions/nginx/check-reload
/usr/libexec/initscripts/legacy-actions/nginx/upgrade
/usr/sbin/nginx
/usr/sbin/nginx-debug nginx服务启动管理的终端命令
/usr/share/doc/nginx-1.16.0
/usr/share/doc/nginx-1.16.0/COPYRIGHT
/usr/share/man/man8/nginx.8.gz nginx的手册和帮助文档
/usr/share/nginx
/usr/share/nginx/html
/usr/share/nginx/html/50x.html
/usr/share/nginx/html/index.html
/var/cache/nginx nginx的缓存目录
/var/log/nginx nginx日志目录
编译参数
nginx -V
[root@rain yum.repos.d]# nginx -V
nginx version: nginx/1.16.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
基本参数
语法
[root@rain yum.repos.d]# cd /etc/nginx
[root@rain nginx]# ls
conf.d koi-utf mime.types nginx.conf uwsgi_params
fastcgi_params koi-win modules scgi_params win-utf
[root@rain nginx]# vim nginx.conf
查看主配置文件
主要有三块
http下可以配置多个站点,即多个server
server 里面有
listen :监听端口
server_name: 虚拟主机或独立域名
location:控制路径的访问
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn; #配置nginx错误日志 位置 级别
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main; #access_log 日志的配置,结合log_format 定义日志级别
sendfile on;
#tcp_nopush on;
keepalive_timeout 65; #超时时间
#gzip on;
include /etc/nginx/conf.d/*.conf; # 这个意思是说他包含了这个目录下的所有*.conf配置文件
}
这个路径下只有一个配置文件
[root@rain nginx]# cd /etc/nginx/conf.d/
[root@rain conf.d]# ls
default.conf
[root@rain conf.d]#
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / { # / 所有路径将进入
root /usr/share/nginx/html; # root 页面路径
index index.html index.htm; # index.html 找不到会找index.htm
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
配置文件修改好需要重启
http请求
yum update curl
[root@rain bin]# curl http://www.baidu.com
查看响应报文
[root@rain bin]# curl -v http://www.baidu.com
重定向到linux空设备
[root@rain bin]# curl -v http://www.baidu.com > /dev/null
大于号是请求 小于号是响应
nginx日志类型
error.log access_log
log_format
[root@rain bin]# tail -f /var/log/nginx/error.log
[root@rain /]# nginx -t -c /etc/nginx/nginx.conf
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@rain /]# nginx -s reload -c /etc/nginx/nginx.conf
[root@rain /]# curl http://127.0.0.1
[root@rain /]# tail -n 200 /var/log/nginx/access.log
127.0.0.1 - - [14/May/2019:23:07:07 +0800] "GET / HTTP/1.1" 200 612 "-" "curl/7.29.0" "-"
127.0.0.1 - - [14/May/2019:23:07:09 +0800] "GET / HTTP/1.1" 200 612 "-" "curl/7.29.0" "-"
[root@rain /]#
内置变量
https://nginx.org/en/docs/
https://nginx.org/en/docs/syslog.html
https://nginx.org/en/docs/http/ngx_http_log_module.html#access_log