FastCGI_cache setup issues


#1

I’m trying to configure fastcgi_cache using this tutorial:

When I add the 3 fastcgi_cache lines to the top of mysite.com config file, I get the following error:

root@server:/etc/nginx/sites-available# nginx -t && service nginx reload
nginx: [emerg] duplicate zone “WORDPRESS” in /etc/nginx/sites-enabled/mysite.com:1
nginx: configuration file /etc/nginx/nginx.conf test failed

I changed the zone name but then get an error about line 2. It seems the fastcgi settings are already loading from /etc/nginx/conf.d/fastcgi.conf

How should I fix this problem?


#2

Hello Jbiggs77,

Its seems like the FastCGI settings is already present in /etc/nginx/conf.d/fastcgi.conf so you don't need to add those 3 lines in your site specific nginx configuration file under the /etc/nginx/sites-available locations.


#3

Nevermind. I ran the command again and it HIT. Thanks for your help!


#4

At very first time the content is not cached so you get the rt-Fastcgi-Cache: MISS When you second time view the same content you get rt-Fastcgi-Cache: HIT


#5

The FastCgi_cache appears to be working but I am getting a 502 bad gateway error when php is stopped.

My website also keeps crashing even though I am on a pretty nice VPS (8gb RAM). Is there a log file I can check to see the cause of the problem?


#6

Make sure before stopping php5-fpm service the web-page is cached. If your requested page is not in cached and php5-fpm in stopped then its give 502 bad gateway

You can monitor the system logs by using following commands cd /var/log tail -f *.log mysql.log mysql.err nginx/*.log


#7

Here are the 2 errors from my nginx error log that I get when the site becomes unresponsive:

2014/02/19 12:33:12 [error] 8959#0: *51273 connect() failed (111: Connection refused) while connecting to upstream, client: XXX.XX.143.110, server: mysite.com, request: "GET /my-page/ HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.mysite.com", referrer: "https://www.google.com/"

2014/02/19 12:33:13 [error] 8960#0: *51129 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: XX.XXX.245.13, server: mysite.com, request: "GET /my-other-page/ HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.mysite.com", referrer: "https://www.google.com/"


#8

Give me the output of following two commands service php5-fpm status ee info


#9

root@server:~# service php5-fpm status php5-fpm start/running, process 1870

root@server:~# ee info Nginx (nginx/1.4.1) Information:

Nginx User: www-data Nginx worker_processes: 4 Nginx worker_connections: 1024 Nginx keepalive_timeout: 65 Nginx fastcgi_read_timeout: 300 Nginx client_max_body_size: 100m Nginx Allowed IP Address: 127.0.0.1 XXX.XX.8.177

PHP (5.5.9-1) Information:

PHP User: www-data PHP expose_php: Off PHP post_max_size: 100M PHP upload_max_filesize: 100M PHP max_execution_time: 300

PHP ping.path: /ping PHP pm.status_path: /status PHP pm.max_requests: 500 PHP pm.max_children: 100 PHP pm.start_servers: 20 PHP pm.min_spare_servers: 10 PHP pm.max_spare_servers: 30 PHP request_terminate_timeout: 300 PHP Fastcgi Listen: 127.0.0.1:9000

MySQL (5.5.35) Information:

MySQL User: mysql MySQL port: 3306 MySQL wait_timeout: 28800 MySQL interactive_timeout: 28800 MySQL Max_used_connections: 19/151 MySQL datadir: /var/lib/mysql/ MySQL socket: /var/run/mysqld/mysqld.sock

EasyEngine (ee) Common Locations:

phpMyAdmin: http://example.com/pma PHP Status: http://example.com/status Nginx Status: http://example.com/nginx_status Opcache & Memcache Status: http://example.com/ee/ EasyEngine Log File: /var/log/easyengine/install.log EasyEngine Configuration File: /etc/easyengine/ee.conf


#10

First Your php5-fpm is listening on 9000 port and the php5-fpm service is running.

2014/02/19 12:33:12 [error] 8959#0: *51273 connect() failed (111: Connection refused) while connecting to upstream, client: XXX.XX.143.110, server: mysite.com, request: “GET /my-page/ HTTP/1.1″, upstream: “fastcgi://127.0.0.1:9000″, host: “www.mysite.com”, referrer: “https://www.google.com/”

Restart the nginx and php5-fpm services will solve this issue service nginx restart && service php5-fpm restart

After restart monitor your logs file and let me know if you still face 502 bad gateway issue


#11

Thank you, the site is now working.

This issue has occurred 3-4 times. The load has not been that high (less than 1500 visitors per hour). Could there be some configuration problem between nginx and fastcgi?


#12

Hello Jbiggs77,

cross check your Memcached size

By default, its 64MB. You may need more.

Open /etc/memcached.conf Look for value -m 64 Change it to -m 1024 Restart memcached service memcached restart

Also refer: https://rtcamp.com/tutorials/php/ https://rtcamp.com/tutorials/nginx/


#13

I wanted to follow up on this. I am still having occasional issues with php5-fpm processes causing very high CPU loads. The server will run fine for months (15-20% CPU usage) and then will spike CPU to 60-110%. Normally, I reboot the server multiple times and it will fix the problem. This obviously is not ideal.

I am having the problem the last few days, here is my current output from top:

top - 09:35:20 up 1 day, 49 min, 1 user, load average: 2.23, 2.16, 2.15 Tasks: 93 total, 2 running, 91 sleeping, 0 stopped, 0 zombie Cpu(s): 31.7%us, 4.2%sy, 0.0%ni, 62.8%id, 0.1%wa, 0.0%hi, 0.0%si, 1.2%st Mem: 8143232k total, 2326060k used, 5817172k free, 412700k buffers Swap: 16777212k total, 0k used, 16777212k free, 661400k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
9503 www-data 20 0 395m 156m 20m S 35 2.0 6:14.12 php5-fpm
9921 www-data 20 0 395m 153m 18m R 34 1.9 0:48.78 php5-fpm
9919 www-data 20 0 312m 75m 20m S 31 0.9 0:53.68 php5-fpm
9210 www-data 20 0 312m 75m 20m S 23 1.0 8:28.71 php5-fpm
9684 www-data 20 0 312m 73m 18m S 21 0.9 2:02.83 php5-fpm
911 mysql 20 0 2579m 86m 7760 S 6 1.1 107:25.90 mysqld
829 root 20 0 15980 712 532 S 0 0.0 0:20.75 irqbalance
1 root 20 0 24332 2280 1344 S 0 0.0 1:17.93 init
2 root 20 0 0 0 0 S 0 0.0 0:00.00 kthreadd
3 root 20 0 0 0 0 S 0 0.0 0:03.64 ksoftirqd/0
4 root 20 0 0 0 0 S 0 0.0 0:07.12 kworker/0:0
5 root 20 0 0 0 0 S 0 0.0 0:00.03 kworker/u:0
6 root RT 0 0 0 0 S 0 0.0 0:00.00 migration/0
7 root RT 0 0 0 0 S 0 0.0 0:02.36 watchdog/0
8 root RT 0 0 0 0 S 0 0.0 0:00.00 migration/1
9 root 20 0 0 0 0 S 0 0.0 0:00.00 kworker/1:0
10 root 20 0 0 0 0 S 0 0.0 0:00.96 ksoftirqd/1


#14