wordpress 訪問很慢 ,進行優化nginx 配置后正常使用

好多次配置不滿意,最後這次勉强能用。
參考地址
https://docs.nginx.com/nginx/admin-guide/content-cache/content-caching/
如果需要複製要修改域名和地址
1、sock也需要進行配置。(之前有過文章)
2、 /var/cache/nginx/cache 需要手動創建(不過裏面沒有東西,不知道咋滴,先用著後期在優化時進行更改,現在速度已經快了很多)

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

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

events {
    worker_connections 10240;
    use epoll;
    multi_accept on;
}

http {
    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_tokens off;
    keepalive_timeout 65;
    client_header_timeout 15s;
    client_body_timeout 15s;
    send_timeout 60s;
    fastcgi_connect_timeout 260;
    fastcgi_send_timeout 260;
    fastcgi_read_timeout 260;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;
    sendfile            on;
    tcp_nopush          on;
    types_hash_max_size 4096;
    gzip  on;
    gzip_min_length 1k;
    gzip_buffers 4 8k;
    gzip_comp_level 6;
    gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
    gzip_vary on;
    gzip_disable "MSIE [1-6]\.";
    proxy_cache_path /var/cache/nginx/cache levels=1:2 keys_zone=imgcache:1024m  inactive=1d max_size=2048m; 
    #mkdir /var/cache/nginx/cache ,chown nginx. /var/cache/nginx/cache
    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;
    server {
        listen         80;
        server_name    xxxxxx.com;

        rewrite ^(.*) http://www.$server_name$1 permanent;
    }
    #三個處理官方看的
    upstream php {
        server unix:/var/run/php-fpm.sock;
        server 127.0.0.1:9000;
    }
    map $uri $blogname{
        ~^(?P<blogpath>/[^/]+/)files/(.*)       $blogpath ;
    }

    map $blogname $blogid{
        default -999;

        #Ref: http://wordpress.org/extend/plugins/nginx-helper/
        #include /var/www/wordpress/wp-content/plugins/nginx-helper/map.conf ;
    }
server {
    listen 80;
    server_name www.xxxx.com;

    root /var/www/html/xxxx;

    index index.php index.html index.htm;
    # 访问路径配置
    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";
    #允许跨域请求的域,* 代表所有
    add_header 'Access-Control-Allow-Origin' *;
    #允许带上cookie请求
    add_header 'Access-Control-Allow-Credentials' 'true';
    #允许请求的方法,比如 GET/POST/PUT/DELETE
    add_header 'Access-Control-Allow-Methods' *;
    #允许请求的header
    add_header 'Access-Control-Allow-Headers' *;
    location / {
    try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

        error_page 404 /index.php;
            location ~ ^(/[^/]+)?/files/(.+) {
            try_files /wp-content/blogs.dir/$blogid/files/$2 /wp-includes/ms-files.php?file=$2 ;
            access_log off;     log_not_found off; expires 1d;
        }

        #avoid php readfile()
        location ^~ /blogs.dir {
        internal;
        alias /var/www/html/xxx/wp-content/blogs.dir ;
        access_log off;     log_not_found off; expires max;
        }

        if (!-e $request_filename) {
            rewrite /wp-admin$ $scheme://$host$uri/ permanent;
            rewrite ^(/[^/]+)?(/wp-.*) $2 last;
            rewrite ^(/[^/]+)?(/.*\.php) $2 last;
        }

        location ~ \.php$ {

            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_index index.php;
            #fastcgi_pass 127.0.0.1:9000;
            fastcgi_pass  php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
        location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
            slice 1m;
            proxy_cache mycache;
            proxy_cache_key   $uri$is_args$args$slice_range;
            proxy_set_header  Range $slice_range;
            proxy_cache_valid 200 1d;
            proxy_cache_use_stale error timeout invalid_header updating http_500 http_503 http_404;
            expires 1d;
            log_not_found off;
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值