在 nginx、CentOS 7 上启用缓存

enable CACHE on nginx, CentOS 7

我是 nginx 的新手,如果之前有人问过这个问题,我很抱歉。

我正在尝试在 nginx 上启用缓存。我找到了解决方案 NGINX Cache

问题是我在 /etc/nginx/ngin.conf 中找到的 nginx.conf 与那里发布的完全不同。所以我有点迷茫,不知道该怎么办。

这是我的 nginx.conf

#user  nginx;
worker_processes  1;

#error_log  /var/log/nginx/error.log;
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;

#pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    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"';

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

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
    #tcp_nodelay        on;

    #gzip  on;
    #gzip_disable "MSIE [1-6]\.(?!.*SV1)";

    server_tokens off;

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

那么我应该如何应用我找到的解决方案或者我应该做其他事情?

请帮忙

看到 nginx.conf 底部的 include /etc/nginx/conf.d/*.conf; 行了吗?这是您要符号链接或保存您的实际主机配置文件的地方。您在其他帖子中看到的那些,通常包含在 server {...}.

您可以随时更改路径或添加另一个路径,一旦 nginx 可以成功解析包含的配置文件(nginx -t 将测试文件),您可以使用 [=14= 优雅地重新启动 nginx ]

更新:

类似下面的内容将进入您的 filename.conf 文件

server {
    listen 80;
    root /somewhere/on/your/machine;

    location / {
        expires 1d;
        # other caching related directives

        gzip            on;
        gzip_min_length 1000;
        gzip_proxied    expired no-cache no-store private auth;
        gzip_types      text/plain application/xml;
        # replace with your own gzip config

    }
}

有关更详细的文档,请参阅 http://nginx.org/en/docs/