Nginx相关

参考:https://juejin.cn/post/7368433531926052874

相关命令
nginx // 启动
nginx -s stop // 停止
nginx -s reload // 重新加载
nginx -t // 检查配置文件的正确性
nginx -v // 查看Nginx版本

ps -ef | grep nginx  // 查看进程命令
more access.log // 查看日志

Nginx上下文
1. main: 全局配置(上下文)
2. events:处理连接配置
3. http: HTTP服务器参数

1. 静态资源服务:前端web
server {
    listen 80;
    server_name example.com;
    location / {
        root /path/to/your/static/files;
        index index.html index.htm;
    }
    location ~* \.(jpg|png|gif|jpeg)$ {
        expires 30d;
        add_header Cache-Control "public";
    }
}

2. 反向代理
server {
    listen 80;
    server_name api.example.com;
    location / {
        proxy_pass http://backend;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

负载均衡
http {
    upstream backend {
        server backend1.example.com;
        server backend2.example.com;
        server backend3.example.com;
    }
    server {
        listen 80;
        server_name example.com;
        location / {
            proxy_pass http://backend;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }
}

posted @ 2024-09-10 09:56  Felix_Openmind  阅读(2)  评论(0编辑  收藏  举报