Table of contents
(4) Security application scenarios
(1) Nginx binary executable file
Second, the deployment of Nginx
(2)/etc/nginx/conf.d/default.conf
3. Encoding configuration files
4. Nginx management command file
Four, Nginx basic configuration
1. Main configuration file configuration
5. Check the configuration syntax and restart the service to take effect
1. Basic overview of Nginx
1 Introduction
nginx is an open source, high performance, reliable HTTP WEB service, proxy service
2. Advantages
High performance, high concurrency, expansion, high reliability, hot deployment, wide application, and efficient network model
3. Application scenarios
(1) Load balancing
(2) Proxy cache
(3) Static resources
(4) Security application scenarios
4. The composition of Nginx
(1) Nginx binary executable file
It is a binary file built by the framework of nginx itself and related modules, and all functions are provided by him
(2) Nginx.conf file
Whether the function is enabled, and how to process the request after it is enabled, is determined by it
(3)access.log
HTTP request information and response information will be recorded
(4)error.log
When some unexpected problems occur, this file can find the problem
Second, the deployment of Nginx
1. Installation method
(1) Source code compilation
The version is random, the installation is complicated, and the upgrade is cumbersome
(2) epel warehouse
The version is low, the installation is simple, and the configuration is not very readable
(3) Official warehouse
Common method, new version, simple installation, high readability of configuration
2. Install Nginx dependencies
[root@oldxu ~] yum install -y gcc gcc-c++ autoconf pcre pcre-devel make automake httpd-tools
3. Configure Nginx source
[root@oldxu ~] vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
4. Install Nginx service
[root@oldxu ~] yum install nginx -y
[root@oldxu ~] systemctl enable nginx
[root@oldxu ~] systemctl start nginx
5. Check the Nginx version
#检查版本
nginx -v
# 检查编译参数
nginx -V
6. Nginx directory structure
rpm -ql nginx
3. Nginx directory structure
1. Main configuration file
(1)/etc/nginx.conf
Configuration file, nginx main configuration file
(2)/etc/nginx/conf.d/default.conf
configuration file, default website configuration file
2. Proxy configuration file
(1)/etc/nginx/fastcgi_params
Configuration file, fastcgi proxy configuration file
(2)/etc/nginx/scgi_params
configuration file, scgi proxy configuration file
(3)/etc/nginx/uwsgi_params
Configuration file, uwsgi proxy configuration file
3. Encoding configuration files
(1)/etc/nginx/win-utf
Configuration file, nginx code conversion mapping file
(2)/etc/nginx/koi-utf
Configuration file, nginx code conversion mapping file
(3)/etc/nginx/requirement_win
Configuration file, nginx code conversion mapping file
(4)/etc/nginx/mime.types
content-Type and extension
4. Nginx management command file
(1)/usr/sbin/nginx
command, nginx command line management terminal tool
(2)/usr/sbin/nginx-debug
command, nginx command line management terminal tool
5. Nginx log related files
(1)/var/log/nginx
Directory, there is a log directory in nginx by default
(2)/etc/logrotate.d/nginx
Configuration file, nginx default log cutting
Four, Nginx basic configuration
1. Main configuration file configuration
[root@oldxu ~]vim /etc/nginx/nginx.conf
#全局
user nginx; #nginx的运行身份为nginx用户;
worker_processes 2; #启动的worker进程数量;
error_log /var/log/nginx/error.log warn;# 错误日志的路径;从warning;
pid /var/run/nginx.pid;# 存储进程的pid Number
# 4c *16GB
events {
worker_connections 1024; # 一个worker最大连接数,worker_connections * worker_processes = 最大连接数
use epoll; # 默认是采用epoll网络IO模型;
}
# 主要负责接受与响应http请求
http {
include /etc/nginx/mime.types;
# 支持的类型:
default_type application/octet-stream;
#默认类型(下载的方式)
# 1.提供下载包zip
# 2.后端并没有将代码解析成功,所以直
接成了下载;
#定义日志的格式
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;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#长连接超时时间;
#gzip on;
include_/etc/nginx/conf.d/*.conf;
#包含的子文件;
}
######
#一个server就是一个站点
server {
listen 80; # 监听的端口
server_name www.oldxu.net; #站点的域名
location / { #uri路径匹配的
root /usr/share/nginx/html; #root:定义网站的路径;
index
index.html index.htm; #index:定义默认返回的页面;
# root+index =
/usr/share/nginx/html/index.html;
}
}
# 一个server就是一个站点
server {
listen 80; # 监听端口80
server_name www.oldxu.net; #站点的域名
location / { #uri路径匹配的
root /usr/share/nginx/html; #root:定义网站的路径;
index index.html index.htm;
#index:定义默认返回的页面;
# root+index
/usr/share/nginx/html/index.html;
}
}
2.Global global module
user www; #Nginx进程所使用的用户
worker_processes 1; #Nginx运行的
work进程数量(建议与CPu数量一致或auto)
error_log /log/nginx/error.log #Nginx错误日志存放路径
pid /var/run/nginx.pid #Nginx服务运行后产生的pid进程号
3.Events event module
events {
worker_connections 25535;#每个worker进程支持的最大连接数
use epoll; #事件驱动模型,epol1默认
}
4.HTTP core module
http { #http层开始
#使用Server配置网站,每个server{}代表一个网
站(简称虚拟主机)
'server' {
listen 80; #监听端口,默认80
server_name bgx.com; #提供的域名
access_log access.log; #该网站的访问日志
#控制网站访问的路径
'location' / {
root /usr/share/nginx/html; #存放网站源代码的位置
index index.html index.htm; #默认返回网站的文件
}
...
#第二个虚拟主机配置
'server' {
}
include /etc/nginx/conf.d/*.conf;#包
含/etc/nginx/conf.d/目录下所有以.conf结尾的文件
#include作用是:简化主配置文件写太多造成臃肿,
这样会让整体的配置文件更加的清晰。
}
#http层结束
5. Check the configuration syntax and restart the service to take effect
[root@oldxu code] nginx -t
[root@oldxu code] systemctl restart nginx
6. Summary of core modules
The http tag is mainly used to solve the user's request and response
The server tag is mainly used to respond to a specific website
The location tag is mainly used to match the specific URI path of the website
Multiple server{} are allowed under http{}, and multiple location{} are allowed under one server{}