網站首頁 編程語言 正文
1.主配置文件與虛擬主機分離
如果虛擬主機很多的話,進行分離看起來會更方便,還可以按功能、業務進行劃分,下面以兩個虛擬主機為例。
完整的除去空行和注釋后的配置文件:
[root@nginx-01 conf]# egrep -v "#|^$" nginx.conf.bak worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
創建/app/nginx/conf目錄下虛擬主機配置目錄
mkdir extra
利用server模塊創建www和bbs兩個虛擬站點
[root@nginx-01 conf]# cat -n nginx.conf [root@nginx-01 conf]# sed -n '10,20p' nginx.conf server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; }
www站點
[root@nginx-01 conf]# cat extra/www.conf server { listen 80; server_name www.yygg.com; location / { root html/www; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }
bbs站點
[root@nginx-01 conf]# cat extra/bbs.conf server { listen 80; server_name bbs.yygg.com; location / { root html/bbs; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html/bbs; } }
主配置文件配置(nginx.conf)
worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; include extra/www.conf; include extra/bbs.conf; }
檢查配置
[root@nginx-01 conf]# /app/nginx/sbin/nginx -t nginx: the configuration file /app/nginx-1.18.0//conf/nginx.conf syntax is ok nginx: configuration file /app/nginx-1.18.0//conf/nginx.conf test is successful
創建站點目錄
[root@nginx-01 conf]# mkdir /app/nginx/html/{www,bbs} [root@nginx-01 conf]# echo "http://www.yygg.com" >>/app/nginx/html/www/index.html [root@nginx-01 conf]# echo "http://bbs.yygg.com" >>/app/nginx/html/bbs/index.html [root@nginx-01 conf]# echo "192.168.1.5 www.yygg.com bbs.yygg.com" >>/etc/hosts
啟動服務并測試
[root@nginx-01 conf]# /app/nginx/sbin/nginx [root@nginx-01 conf]# curl www.yygg.com http://www.yygg.com [root@nginx-01 conf]# curl bbs.yygg.com http://bbs.yygg.com
2.虛擬主機別名設置
以www站點為例,設置別名
所謂別名就是除了主域名外額外設置一個或多個域名
為www.yygg.com
設置別名yygg.com
。
[root@nginx-01 conf]# cat extra/www.conf server { listen 80; server_name www.yygg.com yygg.com; location / { root html/www; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html/www; } }
重啟nginx測試
[root@nginx-01 conf]# /app/nginx/sbin/nginx -s reload [root@nginx-01 conf]# cat /etc/hosts 192.168.1.5 www.yygg.com bbs.yygg.com yygg.com [root@nginx-01 conf]# curl yygg.com http://www.yygg.com
3.Nginx status狀態信息配置
狀態信息記錄使用的是`ngx_http_stub_status_module`模塊實現
輸入/app/nginx/sbin/nginx -V
檢查編譯是否有上述模塊:
nginx version: nginx/1.18.0 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --user=nginx --group=nginx --prefix=/app/nginx-1.18.0/ --with-http_stub_status_module --with-http_ssl_module
創建一個status的虛擬主機,方式參考標題1,status.conf
配置文件如下:
server { listen 80; server_name status.yygg.com; location / { stub_status on; access_log off; } }
主配置文件nginx.conf
追加status虛擬主機配置
sed -i '11 i include extra/status.conf;' nginx.conf
檢查語法并重啟nginx
/app/nginx/sbin/nginx -t /app/nginx/sbin/nginx -s reload
配置hosts解析
192.168.1.5 status.yygg.com
訪問status.yygg.com
查看
[root@nginx-01 conf]# curl status.yygg.com Active connections: 1 server accepts handled requests 4 4 4 Reading: 0 Writing: 1 Waiting: 0
顯示結果解析:
Active connections: 1 ?##正處理的連接數為1
server ?##共處理了4次連接
accepts ?##共創建了4次握手
handled requests ?##共處理了4次請求
Reading ?##讀取到客戶端的Header信息數
Writing ?##返回給客戶端的Header信息數
Waiting ?##NGinx已經處理完正在等候下一次請求的指令的駐留連數
4.增加錯誤日志
error_log語法:
error_log?? ?file?? ?level;
關鍵字不變,file是日志存放位置,level是錯誤日志級別
通常只用warn|error|crit三個級別
配置錯誤日志配置,在nging.conf
文件中worker_processes 1;
下添加
error_loglogs/error_log;
沒錯,就這一行!
原文鏈接:https://yyang.blog.csdn.net/article/details/113753558
相關推薦
- 2022-06-30 Python函數和文件操作詳情_python
- 2022-04-11 Python如何在終端彩色打印輸出_python
- 2022-04-03 Pytorch寫數字識別LeNet模型_python
- 2023-05-18 Go語言中map集合的具體使用_Golang
- 2023-03-26 Kotlin?server多線程編程詳細講解_Android
- 2022-12-08 C語言實現計算圓周長以及面積_C 語言
- 2023-11-13 【云原生】docker設置非root用戶使用權限的方法
- 2022-12-12 C語言入門之查找子串問題_C 語言
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支