Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

用nginx进行load balancing #217

Open
hjyssg opened this issue May 10, 2023 · 1 comment
Open

用nginx进行load balancing #217

hjyssg opened this issue May 10, 2023 · 1 comment
Labels

Comments

@hjyssg
Copy link
Owner

hjyssg commented May 10, 2023

实验性尝试了一下nginx的负载均衡,可以的。挺有意思的,但单进程性能已经够了。

worker_processes auto;

events {
    worker_connections 1024;
}

http {
    # 本地起两个express server
    upstream mybalance01 {
        # weight越高收到的请求越多
        server 127.0.0.1:3000 weight=1 max_fails=5 fail_timeout=3;
        server 127.0.0.1:34213 weight=2 max_fails=5 fail_timeout=3;
    }

    # 缓存目录
    # NOTE:可以用nginx的缓存替换掉代码内部GET缓存
    # proxy_cache_path tmp/nxcache levels=1:2 keys_zone=my_cache:10m inactive=30s;
    # 定义 MIME 类型和默认字符集
    # include /etc/nginx/mime.types;
    # default_type application/octet-stream;
    # include       mime.types;
    # default_type  application/octet-stream;
    # sendfile        on;
    # keepalive_timeout  65;

    # 反向代理配置
    server {
        listen 80;

        # 下载功能进行负载均衡
        location /api/download/ {
            proxy_pass http://mybalance01;
        }

        # 其他请求都主服务器
        # NOTE:哪天数据库不用sqlite,换成mysql之类的,连这个也可以换成负载均衡
        location / {
            proxy_pass http://localhost:3000;
        }
    }
}
@hjyssg hjyssg added the note label May 10, 2023
@hjyssg
Copy link
Owner Author

hjyssg commented May 10, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant