配一下nginx

前提:最大文件打开数需要够大,最好是65535,查看方法ulimit -a

[root@localhost ~]# cat /etc/nginx/nginx.conf

user nginx;
# 这一行为auto
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

include /usr/share/nginx/modules/*.conf;

# 这里改65535
worker_rlimit_nofile 65535;
events {
    # 这里改10000
    worker_connections 10000;
}
http {
    # 这一行取消注释
    server_tokens off;
    ...
}
[root@localhost ~]# cat /etc/nginx/conf.d/api.conf

server {
    listen         80;
    server_name    www.example.cn; #服务器域名
    add_header X-Frame-Options SAMEORIGIN;
    charset UTF-8;
    #log文件地址

    client_max_body_size     100M;
    client_body_buffer_size  100M;

    location /static {
            alias    /project_name/static/;
            index  index.html index.htm index;
    }
    location / {
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_pass  http://127.0.0.1:8000;
        proxy_read_timeout 150s;
        proxy_connect_timeout 75s;
        proxy_set_header Host $proxy_host; # 修改转发请求头,让8080端口的应用可以受到真实的请求
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        
    }

 }
cat /project_name/uwsgi.ini

[uwsgi]
http  = 0.0.0.0:8000
chdir      = /project_name
module     = project_name.wsgi
master     = true
processes    = 16
listen = 10000
vacuum     = false
buffer-size=65536
socket-timeout=100
http-timeout=100
daemonize=/project_name/logs/uwsgi.log

注意:
uwsgi的listen参数需要比net.core.somaxconn

查看net.core.somaxconn值

[root@localhost ~]# sysctl -a |grep somaxconn
net.core.somaxconn = 128

修改net.core.somaxconn参数

在/etc/sysctl.conf文件下新增一行
net.core.somaxconn = 10240

改完执行 sysctl -p 重载参数

修改文件的最大打开数

1.打开/etc/security/limits.conf,里面有很详细的注释,找到如下设置(如果没有就插入)

* soft nofile 65535
* hard nofile 65535

2.编辑/etc/pam.d/common-session,加入一行

session required pam_limits.so

3.编辑/etc/profile,加入

ulimit -SHn 65535

4.设置虚拟内存:

ulimit -v unlimited

关闭旧的session,重连一个 session,验证 ulimit -a

你可能感兴趣的:(配一下nginx)