一,web服務器
1.什么是web服務? web就是B/S架構 2.apache網絡模型 select poll 3.Nginx官網:https://nginx.org/ 軟件:https://nginx.org/download/
二,部署Nignx
1,yum安裝 # 先去官網復制源代碼 [root@web01 ~]# vim /etc/yum.repos.d/nginx.repo [root@web01 ~]# yum install nginx -y [root@web01 ~]# systemctl stop httpd [root@web01 ~]# systemctl start nginx 2,二進制安裝 3,編譯安裝 [root@web01 ~]# wget https://nginx.org/download/nginx-1.20.2.tar.gz [root@web01 ~]# tar -xf nginx-1.20.2.tar.gz [root@web01 nginx-1.20.2]# ./configure [root@web01 nginx-1.20.2]# make [root@web01 nginx-1.20.2]# make install
三,平滑增加Nginx模塊
增加模塊必須重新編譯。 [root@web01 ~]# tar -xf nginx-1.20.2.tar.gz [root@web01 ~]# cd nginx-1.20.2 [root@web01 nginx-1.20.2]#./configure --with-http_ssl_module [root@web01 nginx-1.20.2]#make [root@web01 nginx-1.20.2]#make install
四,Nginx的命令
1、-v : 打印版本號 [root@web01 ~]# nginx -v nginx version: nginx/1.20.2 2、-V : 打印版本號和配置項 [root@web01 ~]# nginx -V nginx version: nginx/1.20.2 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --prefix=/etc/nginx 3、-t : 檢查配置文件 [root@web01 ~]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful 4、-T : 測試配置文件並啟動 5、-q :打印錯誤日志 6、-s : 操作進程 stop :停止 quit :退出 reopen :重啟 reload :重載 7、-p : 指定nginx的工作目錄 8、-e : 指定錯誤日志路徑 9、-c : 指定配置文件的路徑 10、-g : 設置一個全局的Nginx配置項 [root@web01 ~]# nginx -g 'daemon off;'
五,Nginx配置文件
全局配置和模塊配置 1、全局配置 1、user : 指定Nginx的啟動用戶 # www 2、worker_processes : 定義Nginx的worker進程數 auto === CPU數量 3、error_log : 錯誤日志路徑 4、pid : pid的存放文件路徑 5、events : 模塊配置 5.1、worker_connections :每一個worker進程最多同時接入多少個請求 5.2、use : 指定Nginx的網絡模型 6、http : web服務的模塊 6.1、include : 加載外部的配置項 6.2、default_type : 如果找不到文件的類型,則按照指定默認類型處理 6.3、log_format : 定義日志格式 log_format json '{"@timestamp":"$time_iso8601",' '"host":"$server_addr",' '"service":"nginxTest",' '"trace":"$upstream_http_ctx_transaction_id",' '"log":"log",' '"clientip":"$remote_addr",' '"remote_user":"$remote_user",' '"request":"$request",' '"http_user_agent":"$http_user_agent",' '"size":$body_bytes_sent,' '"responsetime":$request_time,' '"upstreamtime":"$upstream_response_time",' '"upstreamhost":"$upstream_addr",' '"http_host":"$host",' '"url":"$uri",' '"domain":"$host",' '"xff":"$http_x_forwarded_for",' '"referer":"$http_referer",' '"status":"$status"}'; access_log /var/log/nginx/access.log json ; 6.4、sendfile : 高效讀取文件 6.5、keepalive_timeout : 長連接保持連接的 HTTP 1.0 短鏈接 HTTP 1.1 長連接 6.6、server : 網址模塊 6.6.1、listen : 監聽的端口 6.6.2、server_name : 定義域名 6.6.3、location : 訪問路徑 6.6.3.1、root : 指定網址路徑 6.6.3.2、index : 指定網址的索引文件
小游戲搭建
1、上傳代碼 [root@wen01 ~]# cd /opt [root@wen01 opt]# mkdir Super_Marie # 上傳腳本 2、編輯配置文件 # cd /etc/nginx/conf.d 第2 cp game.conf game1.conf [root@web01 conf.d]# vim /etc/nginx/conf.d/game.conf # server { listen 80; server_name game.test.com; # location / { root /opt/Super_Marie; # 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、重啟Nginx [root@web01 conf.d]# systemctl restart nginx 5、域名解析 C:\Windows\System32\drivers\etc\hosts 172.16.1.7 game.test.com