nginx(更新中)

Linux安装Nginx

上传nginx-1.21.6.tar.gz

shell 复制代码
yum install -y gcc-c++	zlib zlib-devel	openssl openssl-devel pcre pcre-devel
tar -zxvf nginx-1.21.6.tar.gz
cd nginx-1.21.6/
# 执行配置脚本
./configure --prefix=/usr/local/nginx
# 编译安装
make & make install
# 启动nginx
/usr/local/nginx/sbin/nginx
# 重新加载配置
/usr/local/nginx/sbin/nginx -s reload
# 快速停止
/usr/local/nginx/sbin/nginx -s stop
# 优雅关闭
/usr/local/nginx/sbin/nginx -s quit

目录结构

sbin:存放nginx命令,用于启动nginx

conf:存放nginx配置文件,包含nginx.conf

logs:存放nginx日志

html:存放静态资源,可直接访问

工作流程

nginx启动后会开启一个master进程和至少一个worker进程,master进程负责管理worker进程(启动与停止),worker进程负责处理请求。

nginx.conf

shell 复制代码
# 工作进程数(一般等于服务器的CPU核数,过少会浪费CPU资源,过多会造成上下文切换)
worker_processes  1;

events {
	# 每个worker进程所能建立连接的最大值
    worker_connections  1024;
}


http {
	# 引入mime.types文件
    include       mime.types;
    # 默认让浏览器以流的形式解析返回结果
    default_type  application/octet-stream;
    # 客户端请求文件时,直接转发,不用先放到应用程序内存
    sendfile        on;
 
    keepalive_timeout  65;
    # 一个server对应一个虚拟主机
    server {
        listen       80;
        # 请求通过域名访问时
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }

}
相关推荐
还是大剑师兰特1 天前
解决nginx错误:http://localhost:7000正常,http://localhost:7000/map 报错404
nginx·大剑师
xing-xing2 天前
Docker容器中Nginx站点根目录网页配置访问
nginx·docker
PC2005-cloud2 天前
Nginx 防盗链配置实战:用 referer 模块保护网站静态资源
nginx
PHP实战开发录2 天前
Nginx上传大文件为什么报413
nginx·php·开发
Lsetea2 天前
Nginx报No required SSL certificate was sent:mTLS客户端证书排查
运维·nginx·https·ssl·openssl
szephyr3 天前
HTTPS 证书申请与自动续期:acme.sh + Let‘s Encrypt 完整记录
nginx·https·acme.sh·证书续期
Lsetea4 天前
部署证书后提示“证书名称与输入不匹配”:Safari 报错的三层排查
nginx·https·safari·ssl证书·openssl
打工仔折腾 AI4 天前
FastAPI 从本机到生产服务器:Nginx+Gunicorn+Uvicorn 完整部署实录
人工智能·后端·python·nginx·fastapi·gunicorn
Linux运维技术栈5 天前
如何避免绕过CDN的攻击?基于 CDN 回源请求头鉴权的防御实操与安全性剖析
nginx·安全·cdn
Lsetea5 天前
OpenSSL快速生成域名证书:含SAN的自签命令、验证与排错
nginx·https·ssl证书·openssl·自签证书