1. 가상 호스트에서 기본 구성 파일을 분리합니다.
가상 호스트가 많으면 분리하는 것이 더 편리합니다. 또한, 두 개의 가상 호스트를 예로 들어보겠습니다.
빈 줄과 주석을 제거한 후 구성 파일 완성:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | [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 디렉토리 아래에 가상 호스트 구성 디렉토리를 생성합니다.
서버 모듈을 사용하여 www 및 bbs
1 2 3 4 5 6 7 8 9 10 11 12 13 | [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 사이트 두 개의 가상 사이트를 생성합니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 | [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 사이트
1 2 3 4 5 6 7 8 9 10 11 12 13 | [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)
1 2 3 4 5 6 7 8 9 10 11 12 | 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;
}
|
로그인 후 복사
구성 확인
1 2 3 | [root@nginx-01 conf]# /app/nginx/sbin/nginx -t
nginx: the configuration file /app/nginx-1.18.0
nginx: configuration file /app/nginx-1.18.0
|
로그인 후 복사
사이트 디렉토리 생성
1 2 3 4 | [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
|
로그인 후 복사
서비스 시작 및 테스트
1 2 3 4 5 | [root@nginx-01 conf]# /app/nginx/sbin/nginx
[root@nginx-01 conf]# curl www.yygg.com
http:
[root@nginx-01 conf]# curl bbs.yygg.com
http:
|
로그인 후 복사
2. 예를 들어 www 사이트, 별칭 설정
별칭이라는 것은 기본 도메인 이름 외에 하나 이상의 도메인 이름을 설정하는 것입니다.
에 대해 별칭 <code>yygg.com
을 설정합니다. www.yygg.com.
1 2 3 4 5 6 7 8 9 10 11 12 13 | [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 테스트 다시 시작www.yygg.com
设置别名yygg.com
。
1 2 3 4 5 | [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:
|
로그인 후 복사
重启nginx测试
1 2 3 4 5 | 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
|
로그인 후 복사
3.Nginx status状态信息配置
状态信息记录使用的是`ngx_http_stub_status_module`模块实现
输入/app/nginx/sbin/nginx -V
检查编译是否有上述模块:
1 2 3 4 5 6 7 8 | server {
listen 80;
server_name status.yygg.com;
location / {
stub_status on;
access_log off;
}
}
|
로그인 후 복사
创建一个status的虚拟主机,方式参考标题1,status.conf
配置文件如下:
1 | sed -i '11 i include extra/status.conf;' nginx.conf
|
로그인 후 복사
主配置文件nginx.conf
追加status虚拟主机配置
1 2 | /app/nginx/sbin/nginx -t
/app/nginx/sbin/nginx -s reload
|
로그인 후 복사
检查语法并重启nginx
1 2 3 4 5 | [root@nginx-01 conf]# curl status.yygg.com
Active connections: 1
server accepts handled requests
4 4 4
Reading: 0 Writing: 1 Waiting: 0
|
로그인 후 복사
配置hosts解析
192.168.1.5 status.yygg.com
访问status.yygg.com
查看
rrreee
显示结果解析:
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;
rrreee
3.Nginx 상태 상태 정보 구성
상태 정보 기록은 `ngx_http_stub_status_module` 모듈을 사용하여 구현됩니다
/app/nginx/sbin/nginx -V
를 입력하여 위의 모듈이 있는지 컴파일하십시오:
rrreee
상태 가상 호스트를 생성하십시오. 방법은 제목 1을 참조하십시오.
status.conf
구성 파일은 다음과 같습니다: 🎜rrreee🎜기본 구성 파일 nginx.conf상태 가상 호스트 구성 추가🎜rrreee🎜구문을 확인하고 nginx를 다시 시작🎜rrreee🎜호스트 해상도 구성🎜🎜192.168.1.5 status.yygg.com🎜🎜
status.yygg.com 방문
보기 🎜rrreee🎜표시 결과 분석: 🎜🎜🎜활성 연결: 1 ##처리 중인 연결 수는 1🎜서버 ##총 4개의 연결이 처리되었습니다🎜accept ##총 4개의 핸드셰이크 가 생성되었습니다🎜처리된 요청 ##총 4개의 요청이 처리되었습니다 🎜읽는 중 ##클라이언트에서 읽은 헤더 정보 개수🎜쓰기 ##클라이언트로 반환된 헤더 정보 개수🎜대기 ##NGinx에서 처리한 개수만큼 다음 요청 명령을 기다리는 상주 연결🎜🎜🎜4. 오류 로그 추가 🎜🎜error_log 구문: 🎜🎜🎜error_log 파일 수준; 🎜🎜🎜키워드는 변경되지 않고 유지됩니다. 파일은 로그 저장 위치이고 수준은 오류 로그 수준입니다. 🎜🎜일반적으로 세 가지 수준의 warning|error|crit만 사용됩니다🎜🎜오류 로그 구성을 구성하려면 🎜🎜🎜error_loglogs/error_log;🎜🎜🎜예, 그렇습니다.
worker_processes 1;
아래에 있습니다.
nging.conf
파일! 🎜
위 내용은 Nginx 설치 후 공통 기능을 구성하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!