学习来源:朱双印博主 nginx 篇。 https://www.zsythink.net/archives/category/%e8%bf%90%e7%bb%b4%e7%9b%b8%e5%85%b3/nginx
陶辉陶老师 nginx
《nginx短篇-4 模块、配置指令、块之间的关系》
https://www.zsythink.net/archives/3155
https://blog.csdn.net/u011510825/article/details/50531864 《nginx 中location和root,你确定真的明白他们关系?》
官方参考文档
http://nginx.org/en/docs/dirindex.html
在location中使用root和alias
https://www.zsythink.net/archives/3186
root的例子
alias的例子
nginx短篇(6):访问日志
默认存在的:
http块下设置:
http{
...
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" '
'$connection $upstream_addr '
'$upstream_response_time $request_time';
access_log logs/access.log main;
...
}
nginx短篇(7):进程概述
ps -ef | grep nginx
user nginx; #指定worker进程以nginx用户的身份运行
worker_processes 2;
worker_processes auto;
worker_cpu_affinity 01 10;
或 worker_cpu_affinity auto;
nginx短篇(8):日志切割
《nginx日志自动切割方法》https://www.cnblogs.com/comprehensive/p/12856097.html
nginx短篇(9):信号
nginx -s 可用的:
reopen 对应USR1信号
reload 对应HUP信号
stop 对应TERM信号或者INT信号
quit 对应QUIT信号
”nginx -s reload”命令与”kill -HUP NginxMasterPid”命令的作用是一样的。
我们能向master进程发送如下信号:
TERM或者INT:表示立即停止nginx
QUIT:表示优雅的停止nginx
HUP:重载配置文件
USR1:重新打开日志文件
USR2:热升级nginx程序
WINCH:优雅的关闭相应的worker进程
=分割线=
参考: 《Nginx核心知识100讲学习笔记(陶辉):目录》
https://www.cnblogs.com/luoahong/p/13520306.html
部署goaccess :
https://www.cmdschool.org/archives/2146
goaccess实时HTML输出
#静态HTML输出
goaccess /srv/nginx/logs/access.log -o /srv/nginx/html/report.html --log-format=COMMON
#实时HTML输出,可使用 setsid 后台运行。
setsid goaccess /srv/nginx/logs/access.log -o /srv/nginx/html/report.html --real-time-html --time-format='%H:%M:%S' --date-format='%d/%b/%Y' --log-format=COMBINED
1、关于location下root和alias的“相对路径”的疑惑。
具体参考视频:11. 用 Nginx 搭建一个可用的静态资源 Web 服务器
最初看到博客的 alias dlib/; 这里是个相对路径的写法。 (这里感觉可参考默认的 root html)
我也照葫芦画瓢,将其放到了location1.conf下。后面弄了一会,
nginx.conf所在路径:/srv/nginx/conf 《===》 /srv/nginx/dlib/index.html
其中含有 include /srv/nginx/conf/conf.d/*.conf;
location1.conf所在路径:/srv/nginx/conf/conf.d , 内容如下:
server {
listen 8080;
server_name www.oldhei.com;
location / {
alias dlib/; #这里相对路径为 /srv/nginx/dlib
}
}
他的相对路径为:/srv/nginx/dlib/
回想起以前有个视频说的,就算他是include包含的子配置文件,他是还是以他nginx.conf所在文件夹的相对路径。
2、设置目录浏览autoindex on;
注意这里相对路径和绝对路径的问题,可能会出现404的。(alias dlib/; 和 alias /dlib/;)
https://stackoverflow.com/questions/10631933/nginx-static-file-serving-confusion-with-root-alias
server {
listen 8080;
server_name www.oldhei.com;
location / {
alias dlib/;
autoindex on; #重点这行代码
}
3、控制速度set $limit_rate 1k;
location / {
alias dlib/;
autoindex on;
set $limit_rate 1k;
}
4、nginx 压缩
参考 《nginx压缩》https://www.cnblogs.com/yang-2018/p/11429878.html
http {
......
gzip on;
gzip_min_length 1;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x=httpd-php image/jpeg image/gif image/png;
server {
......
}
END