yum instalt gcc-C++yum instalt - y pcre pcre-devet yum instalt - y zlib zlib-devel 也就是nttpsyum instatt - y opensst openss l-devet tar-zxvf nginx-1. 16.1. tar.gz mkdir / var/ temp/ nginx - p 注:\n代表在命令行中换行,用于提高可读性
配置命令:
命令 | 解释 |
|---|---|
-prefix | 指定nginx 安装目录 |
-pid-path | 指向nginx 的pid |
-lock-path | 锁定安装文件,防止被恶意篡改或误操作 |
-error-log | 错误日志 |
-http-log-path | http日志 |
-with-http gzip static module | 启用gzip模块,在线实时压缩输出数据流 |
-http-client-body-temp-path | 设定客户端请求的临时目录 |
-http-fastcgi-temp-path | 设定fastcgil 临时目录 |
-http-uwsgi-temp-path | 设定uwsgi 临时目录 |
-http-scgi-temp-path | 设定scgi临时目录 |
make make install. /nginx ,停止:./nginx -s stop ,重新加载:./nginx -s reload 注意事项:
worker 进程的用户,指的linux 中的用户,会涉及到nginx操作目录或文件的一些权限,默认为nobody :user root worker 进程工作数设置,一般来说CPU有几个,就设置几个,或者设置为N-1也行:worker _processes 1;debug i info notice warn error I crit I alert emerg ,错误级别从左到右越来越大pid logs/ nginx. pid;events {
#默认使用epoll
use epott;
#每个worker 允许连接的客户端最大连接数
worker connections 10240
}http {
}include mime. types # log_format main '$sremote_ 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;参数名 | 参数意义 |
|---|---|
$remote_addr | 客户端ip |
$remote_user | 远程客户端用户名,一般为:“_” |
$time_local | 时间和时区 |
$request | 请求的url以及method |
$status | 响应状态码 |
$body_bytes_send | 响应客户端内容字节数 |
$http_referer | 记录用户从哪个链接跳转过来的 |
$http_user_agent | 用户所使用的代理,一般来时都是浏览器 |
$http_x_forwarded_for | 通过代理服务器记录客户端的ip |
sendfile 使用高效文件传输,提升传输性能。启用后才能使用tcp_nopush ,是指当数据表累积一定大小后才发送,提高了效率。sendfile on;
tcp_nopush on;keepalive _timeout 设置客户端与服务端请求的超时时间,保证客户端`多次请求的时候不会重复建立新的连接,节约资源损耗。# keepalive_ timeout 0
keepalive _ timeout 65 html/js/css压缩后传输会更快
gzip on;server name localhost 、ip、域名location 请求路由映射,匹配拦截root请求位置server {
listen 88;
server_name localhost;
location / {
root html;
index index.htmt index.htm
}
}本文已收录至我的个人网站:程序员波特,主要记录Java相关技术系列教程,共享电子书、Java学习路线、视频教程、简历模板和面试题等学习资源,让想要学习的你,不再迷茫。