概念:高性能的HTTP和反向代理web服务器,轻量,高并发
环境:
centos7
关闭防火墙
nginx-1.18.0.tar.gz 安装包 源码安装
常用命令:
#创建软链接方便执行
[root@localhost nginx]# ln -s /usr/local/nginx/sbin/nginx /usr/sbin/
#启动服务
[root@localhost nginx]# nginx
#重启服务
[root@localhost nginx]# nginx -s reload
#停止服务
[root@localhost nginx]# nginx -s stop
#检测配置文件是否有语法错误
[root@localhost nginx]# nginx -t
#nginx 启动后会产生 /usr/local/nginx/logs/nginx.pid 文件,记录nginx进程pid
[root@localhost ~]# cat /usr/local/nginx/logs/nginx.pid
7426
配置:
#解压
#tar.gz 压缩包解压
[root@localhost ~]# tar -xvzf nginx-1.18.0.tar.gz
#tar.bz2 压缩包解压
[root@localhost ~]# tar -xvjf nginx-1.18.0.tar.bz2
#配置
#yum 安装需要的依赖
[root@localhost ~]# yum -y install zlib zlib-devel gzip gcc gcc-c++ pcre pcre-devel openssl openssl-devel
[root@localhost ~]# ls
anaconda-ks.cfg nginx-1.18.0 nginx-1.18.0.tar.gz
[root@localhost ~]# cd nginx-1.18.0
[root@localhost nginx-1.18.0]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module
#编译 安装
[root@localhost nginx-1.18.0]# make && make install
[root@localhost nginx-1.18.0]# echo $?
0
#创建软链接方便执行
[root@localhost nginx]# ln -s /usr/local/nginx/sbin/nginx /usr/sbin/
#编辑nginx配置文件
[root@localhost nginx]# cd conf/
[root@localhost conf]# vim nginx.conf
#user nobody;
#进程个数,一般小于cup核数
worker_processes 1;
#错误日志 级别
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#默认进程号存储的文件及目录
#pid logs/nginx.pid;
events {
#每个进程每秒最大的连接数,最大连接数不能超过系统默认允许最大打开文件的数量
worker_connections 1024;
}
http {
include mime.types;
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;
sendfile on;
#tcp_nopush on;
#持久化连接的时间
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access