加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

NGINX缓存错误:与/etc/nginx/nginx.conf中已声明的大小为0的冲

发布时间:2020-12-13 21:13:29 所属栏目:Nginx 来源:网络整理
导读:我目前用于drupal配置的nginx会出现以下错误.不知何故,我无法启用nginx缓存.试过不同的配置,但加班我得到同样的错误.有人可以帮忙吗? nginx: [emerg] the size 5242880 of shared memory zone "MYAPP" conflicts with already declared size 0 in /etc/ngin

我目前用于drupal配置的nginx会出现以下错误.不知何故,我无法启用nginx缓存.试过不同的配置,但加班我得到同样的错误.有人可以帮忙吗?

nginx: [emerg] the size 5242880 of shared memory zone "MYAPP" conflicts with already declared size 0 in /etc/nginx/nginx.conf:51
nginx: configuration file /etc/nginx/nginx.conf test failed

我的nginx.conf

user    nginx;
worker_processes    auto;
http {  include /etc/nginx/conf.d/*.conf;
include /etc/nginx/mime.types;
fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=MYAPP:5M max_size=256M inactive=2h;
fastcgi_cache_key “$scheme$request_method$host$request_uri”;
add_header X-Cache $upstream_cache_status;

## Set a cache_uid variable for authenticated users.
map $http_cookie $cache_uid {
    default nil; # hommage to Lisp :)
    ~SESS[[:alnum:]]+=(?

default.conf

server {
listen  80 default_server;
server_name abc.com;
root /srv/www/abc; ## <== Your only path reference.

#Cache everything by default
set $no_cache 0;
#Don’t cache POST requests
if ($request_method = POST)
{
set $no_cache 1;
}
#Don’t cache if the URL contains a query string
if ($query_string != “”)
{    set $no_cache 1;
}
#Don’t cache the following URLs
if ($request_uri ~* “/(administrator/|login.php)”)
{
set $no_cache 1;
}
#Don’t cache if there is a cookie called PHPSESSID
if ($http_cookie = “PHPSESSID”)
{
set $no_cache 1;
}

        location ~ .php${
fastcgi_split_path_info ^(.+.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_intercept_errors on;
fastcgi_pass   unix:/var/run/php-fpm/rldb.sock;
fastcgi_read_timeout 600;
fastcgi_cache MYAPP;
fastcgi_cache_valid 200 301 30s;
fastcgi_cache_bypass $no_cache;
fastcgi_no_cache $no_cache;
fastcgi_param HTTPS on;
fastcgi_buffer_size 256k;
fastcgi_buffers 256 32k;
fastcgi_connect_timeout 600;
fastcgi_send_timeout 600;

# Set cache key to include identifying components
fastcgi_cache_valid 302     1m;
fastcgi_cache_valid 404     1s;
fastcgi_cache_min_uses 1;
fastcgi_cache_use_stale error timeout invalid_header updating http_500;
fastcgi_ignore_headers Cache-Control Expires;
fastcgi_pass_header Set-Cookie;
fastcgi_pass_header Cookie;

## Add a cache miss/hit status header.
add_header X-Micro-Cache $upstream_cache_status;

## To avoid any interaction with the cache control headers we expire
## everything on this location immediately.
expires epoch;

## Cache locking mechanism for protecting the backend of too many
## simultaneous requests.
fastcgi_cache_lock on;
}
最佳答案
把include包括在/etc/nginx/conf.d/*.conf中;缓存声明之后,而不是之前.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读