阿里云2核8G服务器 Nginx 优化配置

配置文件:nginx.conf

user  www;
worker_processes  2; #默认进程数为1,为提高性能官方的建议是修改成cpu的内核数,可以减少机器io带来的影响

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

worker_rlimit_nofile 65535; #配置要和系统的单进程打开文件数一致,可通过 ulimit -n 命令查询

events {
    use epoll;
    
    #根据系统的最大打开文件数来调整,worker_connections进程连接数量要小于等于系统的最大打开文件数
    #worker_connections进程连接数量真实数量 = worker_connections*worker_process
    worker_connections  20480; # 根据本例,理论上单个进程允许的客户端最大连接数(65535/2)
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    client_max_body_size 25m;
    client_header_buffer_size 4k;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    server_tokens off; #隐藏nginx版本号

    access_log off; #关闭请求日志优化性能
    #access_log  /var/log/nginx/access.log  main;

    open_file_cache max=65535 inactive=20s;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  60;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

配置文件:/etc/nginx/conf.d/*.conf

server {
    listen       80;
    server_name  xxx.com;
    return       301 https://$server_name$request_uri;
}

server {
    listen 443 ssl http2;
    server_name xxx.com;
    root  /data/unity-pc/public;
    index index.html index.htm index.php;

    ssl_certificate   /var/ssl/4517843_xxx.pem;
    ssl_certificate_key  /var/ssl/4517843_xxxx.key;
    ssl_session_cache shared:SSL:1m;
    ssl_session_timeout 10m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;

    location / {
    	try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
       	fastcgi_pass   127.0.0.1:9000;
     	fastcgi_buffer_size 64k;
        fastcgi_buffers 4 64k;
        fastcgi_busy_buffers_size 128k;
        fastcgi_temp_file_write_size 128k;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
        include  fastcgi_params;
    }

    location ~ .*\.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm)$ {
        expires 2d;
    }
 
    location ~ .*\.(?:js|css)$ {
        expires 8h;
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

吹落的树叶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值