LNMP环境优化实践 - AFF大佬 - 分享有价值的主机信息和服务器运维编程技术
当前位置: 主页 » 技术干货 » LNMP环境优化实践

LNMP环境优化实践

   affdalao      2016年06月22日   阅读 130 次     0 评论   Tags:

1、优化nginx配置文件
vi /etc/nginx/nginx.conf

user  nginx;
worker_processes  1;

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


events {
    use epoll;
    worker_connections  1024;
    multi_accept on;

}


http {
    include       /etc/nginx/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"';

    access_log  /var/log/nginx/access.log  main;

    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 50m;

    server_tokens off;
    sendfile on;
    tcp_nopush     on;
    tcp_nodelay on;
    keepalive_timeout 10;

    fastcgi_connect_timeout 300; #如果你不使用FastCGI,请用井号注释该段每一行
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 256k;

    gzip on; #如果你不使用GZip,请用井号注释该段每一行
    gzip_min_length  1k;
    gzip_buffers     4 16k;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_types       text/plain application/x-javascript application/javascript text/css application/xml;
    gzip_vary on;
    gzip_proxied        expired no-cache no-store private auth;
    gzip_disable        "MSIE [1-6]\.";

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

1.2、nginx网站配置

    server {
        listen       80;
        listen       443 ssl http2;
        server_name  affdalao.com affdalao.com;

        ssl_certificate      /etc/letsencrypt/live/affdalao.com/fullchain.pem;
        ssl_certificate_key  /etc/letsencrypt/live/affdalao.com/privkey.pem;

    ssl_session_cache shared:SSL:10m;
        ssl_session_timeout 10m;
    keepalive_timeout   70;
        ssl_buffer_size 8k;
        ssl_stapling on;
        ssl_stapling_verify on;
    ssl_session_tickets      on;
    resolver 223.5.5.5 223.6.6.6;
    ssl_protocols        TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers 'AES128+EECDH:AES128+EDH:!aNULL';    
    ssl_prefer_server_ciphers on;
    add_header Strict-Transport-Security max-age=15768000;

        location / {
            root   /home/affdalao.com;
            index  index.php index.html index.htm;

        if (!-e $request_filename) {
            rewrite ^(.*)$ /index.php$1 last;
        }

        }


#        location ~ \.php$ {
    location ~ .*\.php(\/.*)*$ { 
           root           /home/affdalao.com;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /home/affdalao.com$fastcgi_script_name;
            include        fastcgi_params;
        }

    }

2.优化php.ini

vi /usr/local/php/etc/php.ini

zend_extension=opcache.so
opcache.enable=1
opcache.enable_cli=1"
opcache.file_cache=/tmp
expose_php = Off
date.timezone = "Asia/Hong_Kong"

2.1、优化www.conf

vi /usr/local/php/etc/php-fpm.d/www.conf
mkdir -p /var/run/php-fpm
touch /var/run/php-fpm/php-fpm.sock
user = nginx
group = nginx

2.2、点击下载PHP配置文件

  • 版权声明:本文版权归AFF大佬和原作者所有,未经许可不得转载。文章部分来源于网络仅代表作者看法,如有不同观点,欢迎进行交流。除非注明,文章均由 AFF大佬 整理发布,欢迎转载,转载请带版权。

  • 来源:AFF大佬 ( https://affdalao.com/ ),分享有价值的主机信息和服务器运维编程技术。
  • 链接:https://affdalao.com/8.html
  • 评论(0

    1. 还没有任何评论,你来说两句吧

    发表评论

    电子邮件地址不会被公开。 必填项已用*标注