nginx编译安装
一、Nginx是什么?
Nginx是web服务软件。
Nginx是一个开源且高性能、可靠的http web服务、代理服务的软件
1、开源
2、Nginx web服务器
3、Nginx是俄罗斯一个程序员
4、Nginx还是代理
二、Nginx和Apache之间对比
网络模型:
select 性能最低
poll 性能稍好
epoll 性能最强
Apache : select
Nginx : epoll
三、安装Nginx
wget http://nginx.org/download/nginx-1.20.1.tar.gz tar -xf nginx-1.20.1.tar.gz cd nginx-1.20.1 ./configure --with-http_ssl_module --with-http_v2_module --with-stream --prefix=/usr/local/nginx make && make install
echo "export PATH=$PATH:/usr/local/nginx/sbin" >> /etc/profile #设置环境变量
source /etc/profile
root@web03 sbin]# vi /usr/lib/systemd/system/nginx.service #加入system管理
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl start nginx
四、nginx常用命令
nginx -v : 展示nginx的版本号
nginx -V :展示nginx版本号和配置参数
nginx -t : 测试配置文件
nginx -T : 测试配置文件并打印
nginx -q : 静默输出错误信息
nginx -s : 向nginx发送信号
nginx -p : 指定运行的家目录
nginx -e : 设置错误日志的路径
nginx -c : 设置配置文件
nginx -g : 临时设置配置项
五、nginx配置文件详解
# 工作进程启动用户
user nginx;
# 启动的worker进程数
worker_processes auto;
# 指定错误日志的路径
error_log /var/log/nginx/error.log notice;
# 指定nginx进程的PID
pid /var/run/nginx.pid;
# 配置事件
events {
# worker进程中最大的连接数
worker_connections 1024;
}
# http配置模块
http {
# include 是讲其他文件导入进来
include /etc/nginx/mime.types;
# default_type 指定nginx处理文件的默认类型
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 /var/log/nginx/access.log main;
# 高效读取文件
sendfile on;
#tcp_nopush on;
# 长连接的超时时间
keepalive_timeout 65;
# 设置GZIP压缩
#gzip on;
# 加载其他的配置文件
include /etc/nginx/conf.d/*.conf;
}
game.conf
# 每一个server都代表一个网站(nginx是支持多个网站)
server {
# 指定当前网站的域名
server_name www.baidu.com;
# 指定当前网站的端口
listen 80;
# 指定一个访问路径
location / {
# 指定站点目录
root /opt/html;
# 指定默认访问的文件
index index.html;
}
}
nginx和Apache性能对比
https://www.cnblogs.com/RRecal/p/15467229.html

浙公网安备 33010602011771号