A、nginxの基本的な導入
1.1:nginxのは何ですか
nginxのは、オープンソース、高性能、信頼性のHttp Webサービス、代理店サービスです。
ソースコードnginxののへの直接アクセスに反映オープンソース、
同時サポート多数の反射性能、
信頼性の高い、安定性は、サービスに反映され
1.2:なぜnginxの
- 高性能、高同時実行
- 高いスケーラビリティ
- 高信頼性
- ホット・デプロイ
- Epoolを使用してnginxのネットワークモデル
- 第二に、城の更新技術を削減しながら、メンテナンス城を減らし、nginxの統一技術スタックを使用して
1.3:Nginxはどのような使用シナリオ
nginxの主な使用シナリオは、私は、三つにすなわち静的リソースサービス、代理店リソースサービス、セキュリティサービスをまとめました。
1、nginx web服务
2、nginx反向代理
3、nginx反向代理-->负载均衡
4、nginx反向代理-->缓存
5、nginx静态加速
6、nginx动静分离
7、nginx全栈https
二、nginxのインストールと展開
1、配置Nginx官方源(推荐)
[root@web01 ~]# 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
module_hotfixes=true
[root@web01 ~]# yum install nginx -y
2、nginx运行一个网站
[root@web01 conf.d]# gzip default.conf
[root@web01 conf.d]# cat test.com.conf
server {
listen 80;
server_name test.com;
location / {
root /code;
index index.html;
}
}
3、语法检查
[root@web01 conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
4、上传代码
[root@web01 code]# git clone https://gitee.com/linex/battlecity.git
[root@web01 code]# mv battlecity/* ./
5、重启服务
[root@web01 code]# systemctl restart nginx
6、访问测试
注意:使用域名请配置Windows Host劫持,否则无法访问自己配置的域名(host文件位置百度)
三、nginxの設定ファイルは詳細
user nginx; # Nginx进程的运行用户身份
worker_processes 1; # Nginx运行的worker进程数
error_log /var/log/nginx/error.log warn; # Nginx错误日志存放的路径
pid /var/run/nginx.pid; # Nginx进程运行的PID号
events {
worker_connections 1024; # 每个worker进程能接受的最大连接数
use epoll;
}
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"';
#访问日志的路径 访问日志的存储格式是main格式, main格式在log_format中进行定义
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65; # 超时时间
#gzip on;
include /etc/nginx/conf.d/*.conf; # 包含 *.conf
#server<--定义网站
server {
listen 80; # 监听80端口
server_name localhost; # 网站的域名
location / { # 匹配网站的uri
root /usr/share/nginx/html; # 返回资源的具体路径
index index.html index.htm; # 返回的具体资源名称
}
}