美文网首页
配一下nginx

配一下nginx

作者: aq_wzj | 来源:发表于2021-08-26 11:51 被阅读0次

前提:最大文件打开数需要够大,最好是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

相关文章

  • 树莓派linux+nginx+uwsgi+flask配置运行网站

    安装nginx: sudo apt-get install nginx 分别说一下nginx配置文件和uwsgi配...

  • 配一下nginx

    前提:最大文件打开数需要够大,最好是65535,查看方法ulimit -a 注意:uwsgi的listen参数需要...

  • 通过Brew安装相关服务记录

    Nginx 在/usr/local/etc/nginx/nginx.conf文件中。每次修改nginx.conf配...

  • nginx(四、配置反向代理、负载均衡、https)

    /etc/nginx/nginx.conf /etc/nginx/conf.d/myconfig.conf 这个配...

  • 停止重启nignx

    nginx -s stop 强制关闭 nginx -s quit 安全关闭 nginx -s reload 改变配...

  • 编译安装nginx和勾结php

    来写一下,怎么安装一个nginx网上面经常有说nginx比httpd屌之类的话。就来比较一下把。不过他们两个经常配...

  • Nginx使用

    Nginx [toc] nginx命令 参数 Nginx启动 通过指定配置文件启动 配置文件语法检查 Nginx配...

  • 监控Nginx

    启动nginx_exporter 配置nginx 修改nginx.conf 在http模块中添加内容如下: 添加配...

  • Nginx基本使用

    一、安装部署Nginx 1、安装依赖 2、下载安装Nginx 3、启动Nginx Nginx默认安装路路径 访问配...

  • nginx安装

    安装软件 下载 配置nginx 完成之后的配置文件见:/opt/nginx/conf/nginx.conf,参数配...

网友评论

      本文标题:配一下nginx

      本文链接:https://www.haomeiwen.com/subject/lpzyiltx.html