安装插件
1. gcc
gcc -v
yum -y install gcc
2. pcre、pcre-devel
pcre是一个perl库,包括perl兼容的正则表达式库,nginx的http模块使用pcre来解析正则表达式
yum install -y pcre pcre-devel
3. List item
zlib库提供了很多种压缩和解压缩方式nginx使用zlib对http包的内容进行gzip
yum install -y zlib zlib-devel
4. openssl
web安全通信
yum install -y openssl openssl-devel
Nginx
直接下载或网页下载:
wget http://nginx.org/download/nginx-1.20.1.tar.gz
解压:
tar -zxvf nginx-1.20.1.tar.gz
进入文件夹:
cd nginx-1.20.1
加入配置模块:
./configure --prefix=/usr/local/nginx --with-stream --with-http_stub_status_module --with-http_ssl_module
构建:
make && make install
默认路径修改配置文件:
/usr/local/nginx/conf/nginx.conf
启动ngnix:
cd /usr/local/nginx/sbin
./nginx
检查配置文件:
./nginx -t
停止,重载
./nginx -s stop
./nginx -s reload
查看启动状态:
ps -ef | grep nginx
查看错误日志:
/usr/local/nginx/logs/error.log
配置文件:
#user nobody;
worker_processes 1; #工作进程:数目。根据硬件调整,通常等于cpu数量或者2倍cpu数量。
#错误日志存放路径
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid; # nginx进程pid存放路径
events {
worker_connections 1024; # 工作进程的最大连接数量
}
http {
include mime.types; #指定mime类型,由mime.type来定义
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; #用log_format指令设置日志格式后,需要用access_log来指定日志文件存放路径
#access_log off; 关闭正常运行日志,生产环境量过大时建议使用此配置
sendfile on; #指定nginx是否调用sendfile函数来输出文件,对于普通应用,必须设置on。
如果用来进行下载等应用磁盘io重负载应用,可设着off,以平衡磁盘与网络io处理速度,降低系统uptime。
#tcp_nopush on; #此选项允许或禁止使用socket的TCP_CORK的选项,此选项仅在sendfile的时候使用
#keepalive_timeout 0; #keepalive超时时间
keepalive_timeout 65;
#gzip on; #开启gzip压缩服务
#虚拟主机
server {
listen 80; #配置监听端口号
server_name localhost; #配置访问域名,域名可以有多个,用空格隔开
#charset koi8-r; #字符集设置
#access_log logs/host.access.log main; # 正常访问日志,如果访问量大可以不打印,防止存储空间不够
access_log off;
location / {
root html;
index index.html index.htm;
}
#错误跳转页
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
关闭正常日志输出:
access_log off;