先源码安一下nginx
点击下载源码包
解压
tar xfz nginx-1.16.1.tar.gz
安装依赖
yum -y install gcc gcc-c++ pcre-devel zlib-devel
源码安装
cd nginx-1.16.1/
./configure && make && make install
启动一下访问一下
/usr/local/nginx/sbin/nginx
进入配置文件
vim /usr/local/nginx/conf/nginx.conf
隐藏版本号
放到httpd模块中
server_tokens off;
在平滑重启查看
/usr/local/nginx/sbin/nginx -s reload
worker_processes 8; 优化nginx worker进程数(8是CPU的倍数)
worker_rlimit_nofile 65535; 优化nginx worker进程最大打开文件数
worker_connections 65535; 优化nginx worker单个进程允许的最大连接数
sendfile on; 开启高效文件传输模式 放在http模块
keepalived_timeout 65; 优化nginx连接超时时间
gzip on; nginx图片压缩
nginx配置文件详解
主要模块:
main:配置一些影响整体运行参数
events:配置和服务器性能相关的参数
http块:包含server模块,location模块。包含嵌套多个server,配置代理、缓存、日志等大部分功能
server块:可以嵌套多个location块。配置虚拟主机相关参数
location:配置请求路由:各页面的处理情况
来源:CSDN
作者:xiaoxiao12138
链接:https://blog.csdn.net/xiaoxiao12138/article/details/103829603