安装nginx并进行配置(记录来源于马哥linux运维教程 三)

时间:2021-6-19 作者:admin

nginx最常见配置
1、woker_connections:
最大并发数目:woker_proces*woker_conections
2、user[epoil]/[rgsig]/[select]/[poil]
//定义事件使用模型,建议让nginx自动选择
3、accept_mutex[on|off] 互斥锁机制,负载均衡锁
//on启用时候 让多个woker轮流的序列化的响应请求
4、lock_tile /PATH/TO/LOCK_FILE;

更多在官方文档

https://www.nginx.cn/doc/

性能优化参见:

https://www.cnblogs.com/itcomputer/p/6441998.html

最常用的是:
user nignx nginx 用户
woker_process 进程数目
woker_priority 指明worker进程的nice值,提高优先级。
woker_connections1024;

企业级别配置解析参考

https://blog.csdn.net/weixin_44313519/article/details/91865439


#user  nobody;
worker_processes  2;

#error_log  /home/usr/local/nginx/logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
pid        logs/nginx.pid;


events {
    worker_connections  10240;
}


http {
    client_header_buffer_size 16k;
    large_client_header_buffers 4 16k;

    include       mime.types;
    default_type  application/octet-stream;


    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
        #tcp_nopush     on;
    keepalive_timeout  65;

    upstream admin {
        server 127.0.0.1:8081;
    }

    upstream api {
        server 127.0.0.1:8080;
    }

    upstream wechat {
        server 127.0.0.1:8082;
    }

    upstream www {
        server 127.0.0.1:8083;
    }

    upstream  svn {
        server 10.162.5.36:3690;
    }

    upstream testwechat {
        server 10.162.5.72:8089;
    }

    upstream testapi {
        server 10.162.5.38:8900;
    }
    upstream yanzheng {
        server 127.0.0.1:8084;
    }



    upstream testadmin {
        server 10.162.5.72:8091;
    }


server {
        listen 80;
        server_name localhost;
        charset utf-8;
        root html;
        access_log  logs/sclzsi.log  main;
        }

server {
        listen       80;
        server_name  www.sclzsi.com;

        charset utf-8;

        location / {
                rewrite . http://182.130.246.34:9528/msimsWebM/;
        }

        access_log  logs/sclzsi.log  main;

       }


server {
        listen       80;
        server_name sclzsi.cn;

        charset utf-8;

        location / {
                proxy_pass  http://www;

        }
        access_log  logs/www.log  main;


        }

server {
        listen       80;
        server_name twechat.sclzsi.cn 220.166.104.172;

        charset utf-8;

        location / {
                proxy_pass  http://10.162.5.39:8100;
                proxy_buffer_size 64k;
                proxy_buffers   4 32k;
                proxy_busy_buffers_size 64k;

        }

        location ^~ /vx/ {
                proxy_pass http://10.162.5.39/;
                proxy_buffer_size 64k;
                proxy_buffers   4 32k;
                proxy_busy_buffers_size 64k;
        }

        location ^~ /attachment/ {
                proxy_pass http://10.162.5.39:8201/;
                proxy_buffer_size 64k;
                proxy_buffers   4 32k;
                proxy_busy_buffers_size 64k;

        }

        location ^~ /admin/ {
                proxy_pass http://10.162.5.39:8200/;
                proxy_buffer_size 64k;
                proxy_buffers   4 32k;
                proxy_busy_buffers_size 64k;

        }

        location ^~ /vx-si/ {
                proxy_pass http://10.162.5.37:8020/;
                proxy_buffer_size 64k;
                proxy_buffers   4 32k;
                proxy_busy_buffers_size 64k;

        }
}

#以下属性中,以ssl开头的属性表示与证书配置有关。
server {
        listen 443 ssl;
        #配置HTTPS的默认访问端口为443。
        #如果未在此处配置HTTPS的默认访问端口,可能会造成Nginx无法启动。
        #如果您使用Nginx 1.15.0及以上版本,请使用listen 443 ssl代替listen 443和ssl on。
        server_name xcx.sclzsi.cn; #需要将yourdomain.com替换成证书绑定的域名。
        root html;
        index index.html index.htm;
        ssl_certificate cert/cert-file-name-pem.pem;  #需要将cert-file-name.pem替换成已上传的证书文件的名称。
        ssl_certificate_key cert/cert-file-name-key.key; #需要将cert-file-name.key替换成已上传的证书密钥文件的名称。
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        #表示使用的加密套件的类型。
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #表示使用的TLS协议的类型。
        ssl_prefer_server_ciphers on;
        location / {
                proxy_pass  http://10.162.5.38:8880;
                root html;  #站点目录。
                index index.html index.htm;
        }
}


server {
        listen       80;
        server_name xcx.sclzsi.cn;
        rewrite ^(.*)$ https://$host$1; #将所有HTTP请求通过rewrite指令重定向到HTTPS。
        charset utf-8;

        location / {
                proxy_pass  http://10.162.5.38:8880;

        }
}
#内网访问图片服务器
server {
        listen       80;
        server_name xcx.sclzsi.cn;
        location ~ .*\.(gif|jpg|jpeg|png)$ {
            expires 24h;
            root /www/xcx/;#指定图片存放路径
            proxy_store on;
            proxy_store_access user:rw group:rw all:rw;
            proxy_temp_path         /;#代理临时路径
            proxy_redirect          off;

            proxy_set_header        Host xcx.sclzsi.cn;
            proxy_set_header        X-Real-IP $remote_addr;
            proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for; 
            client_max_body_size    10m;
            client_body_buffer_size 1280k;
            proxy_connect_timeout   900;
            proxy_send_timeout      900;
            proxy_read_timeout      900;
            proxy_buffer_size       40k;
            proxy_buffers           40 320k;
            proxy_busy_buffers_size 640k;
            proxy_temp_file_write_size 640k;
            if ( !-e $request_filename)
            {
                 proxy_pass  http://10.162.5.38:8880;#代理访问地址
            }
        }

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

        error_page   500 =200 502 503 504  /50x.html;  //以指定的响应码响应
        location = /50x.html {
            root   html;
        }

}

server {
        listen       80;
        server_name www.sclzsi.cn;

        charset utf-8;
        location /WechatIMG49.jpeg {
                root html;
        }
        location /WechatIMG50.jpeg {
                root html;
        }

        location /logs.tar.gz {
                root html;
        }
        location / {
                proxy_pass  http://www;
        }
        access_log  logs/www.log  main;


        }


server {
        listen       80;
        server_name svn.sclzsi.cn;

        charset utf-8;

        location / {
                proxy_pass  http://svn;
                client_max_body_size  20m;
        }
        access_log  logs/svn.log  main;


        }


server {
        listen       80;
        server_name  admin.sclzsi.cn;

        charset utf-8;

        location / {
                proxy_pass  http://admin;

        }

        access_log  logs/admin.log  main;

       }


server {
        listen       80;
        server_name  api.sclzsi.cn;

        charset utf-8;

        location / {
                proxy_pass  http://api;
        }

        access_log  logs/api.log  main;

       }


server {
        listen       80;
        server_name  wechat.sclzsi.cn;

        charset utf-8;
        location /MP_verify_h7FTZfPnx5k3ebAQ.txt {
                root html;
        }

        location / {
                proxy_pass  http://wechat;
        }

        access_log  logs/wechat.log  main;

       }



server {
        listen       80;
        server_name  www.sclzsi.com;

        charset utf-8;

        location / {
                proxy_pass  http://www;
        }

        access_log  logs/www.log  main;

       }

server {
        listen       80;
        server_name  svn.sclzsi.com;

        charset utf-8;

        location / {
                proxy_pass  http://svn;
                client_max_body_size  20m;
        }

        access_log  logs/svn.log  main;

       }


server {
        listen       80;
        server_name  admin.sclzsi.com;

        charset utf-8;

        location / {
                proxy_pass  http://admin;
        }

        access_log  logs/admin.log  main;

       }

server {
        listen       80;
        server_name  api.sclzsi.com;

        charset utf-8;

        location / {
                proxy_pass  http://api;
        }

        access_log  logs/api.log  main;

       }

server {
        listen       80;
        server_name  wechat.sclzsi.com;

        charset utf-8;

        location / {
                proxy_pass  http://wechat;
        }

        access_log  logs/wechat.log  main;

       }

server {
        listen       80;
        server_name  testwechat.sclzsi.com;

        charset utf-8;

        location / {
                proxy_pass  http://testwechat;
        }

        access_log  logs/testwechat.log  main;

       }

server {
        listen       80;
        server_name  testapi.sclzsi.cn;

        charset utf-8;

        location / {
                proxy_pass  http://testapi;
        }

        access_log  logs/testapi.log  main;

       }

server {
        listen       80;
        server_name  testadmin.sclzsi.com;

        charset utf-8;

        location / {
                proxy_pass  http://testadmin;
        }

        access_log  logs/testadmin.log  main;

       }
server {
        listen       80;
        server_name  yz.sclzsi.cn;

        charset utf-8;

        location / {
                proxy_pass  http://yanzheng;
        }

        access_log  logs/yanzheng.log  main;

       }




}

声明:本文内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎进行举报,并提供相关证据,工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。