时间:2023-07-17 14:24:01 | 来源:网站运营
时间:2023-07-17 14:24:01 来源:网站运营
一份配置清单详解Nginx服务器配置:看到了下文中的包含了 “小猪佩琪色” 的配图了吗,嘿嘿,我们开始吧!
user nobody nobody;worker_processes 3;error_log logs/error.log;pid logs/nginx.pid;events { use epoll; worker_connections 1024;}http { include 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"'; access_log logs/access.log main; sendfile on; keepalive_timeout 65; server { listen 8088; server_name codesheep; access_log /codesheep/webserver/server1/log/access.log; error_page 404 /404.html; location /server1/location1 { root /codesheep/webserver; index index.server2-location1.htm; } location /server1/location2 { root /codesheep/webserver; index index.server2-location2.htm; } } server { listen 8089; server_name 192.168.31.177; access_log /codesheep/webserver/server2/log/access.log; error_page 404 /404.html; location /server2/location1 { root /codesheep/webserver; index index.server2-location1.htm; } location /srv2/loc2 { alias /codesheep/webserver/server2/location2/; index index.server2-location2.htm; } location = /404.html { root /codesheep/webserver/; index 404.html; } }}
接下来就来详细剖析以下配置文件中各个指令的含义⬇️user user [group];
user nobody nobody
,则默认所有用户都可以启动Nginx进程worker_processes number | auto;
ps -aux | grep nginx
很明显,理解 worker_processes
这个指令的含义就很容易了pid file;
logs/nginx.pid
error_log file | stderr;
include file;
accept_mutex on | off;
multi_accept on | off;
use model;
worker_connections number;
include mime.types;default_type mime-type;
cat mime.types
来查看mime.types文件内容,我们发现其就是一个types结构,里面包含了各种浏览器能够识别的MIME类型以及对应类型的文件后缀名字,如下所示:access_log path [format];
log_format
定义的格式sendfile on | off;sendfile_max_chunk size;
keepalive_timeout timeout [header_timeout];
keepalive_requests number;
listen IP[:PORT];
listen PORT;
listen 192.168.31.177:8080; # 监听具体IP和具体端口上的连接listen 192.168.31.177; # 监听IP上所有端口上的连接listen 8080; # 监听具体端口上的所有IP的连接
server_name name1 name2 ...
server_name ~^www/d+/.myserver/.com$
此时表示该虚拟主机可以接收类似域名 http://www1.myserver.com 等的请求而拒绝 www.myserver.com 的域名请求,所以说用正则表达式可以实现更精准的控制server_name IP地址
location [ = | ~ | ~* | ^~ ] uri {...}
root path;
alias path; # path为修改后的根路径
index file ......
关键词:配置,服务,清单