目录
N:nginx web
轻量级软件,支持庞大的并发访问。
配置nginx
下载
wget http://nginx.org/download/nginx-1.20.2.tar.gz
解压
tar–zxvf nginx-1.20.2.tar.gz
进入
cd nginx-1.20.2
配置
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx
编译
make
安装
make install
如果报错误提示:
./configure: error: the HTTP rewrite module requires the PCRE library.表示需要安装依赖
安装依赖
yum -y install pcre-devel openssl openssl-devel
Usage: nginx [-?hvVtTq] [-s signal] [-p prefix] [-e filename] [-c filename] [-g directives] Options: -?,-h : this help -v : show version and exit -V : show version and configure options then exit -t : test configuration and exit -T : test configuration, dump it and exit -q : suppress non-error messages during configuration testing -s signal : send signal to a master process: stop, quit, reopen, reload -p prefix : set prefix path (default: /usr/local/nginx/) -e filename : set error log file (default: logs/error.log) -c filename : set configuration file (default: conf/nginx.conf) -g directives : set global directives out of configuration file
启动nginx服务
./usr/local/nginx/sbin/nginx
如果报错
表示地址或者端口被占用,当出现这个错误时,可能存在80端口被占用的情况。
ss -antpl | grep 80
可以在windows上进行访问来验证。
该主页存放于/usr/local/nginx/html/下的index.html。
cat /usr/local/nginx/html/index.html
停止nginx服务
./usr/local/nginx/sbin/nginx -s stop
重要文件理解
_temp:临时目录
conf:配置文件
nginx.conf文件包括三部分:
//全局配置 #user nobody;//运行用户如果未指定 worker_processes 1;//工作进程数(根据cpu核心数设定) #error_log logs/error.log;//错误日志的文件位置 #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid;//pid文件位置
//I/O事件配置 events { worker_connections 1024;//每个进程处理1024连接 }
//HTTP配置部分 http { include mime.types;//文件拓展名与文件类型映射表 default_type application/octet-stream;//默认文件类型 sendfile on;//支持文件发送(下载) #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65;//连接保持超时时间,单位秒 server {//web服务监听配置 listen 80;//监听80端口 server_name localhost;//网站名称 #charset koi8-r; location / {//定义安装目录为软件根目录 root html;//网页存放目录 index index.html index.htm;//默认索引页 } location = /50x.html {//错误页面配置 root html; }