我在socket.io和nginx配置方面遇到了一些问题。
在网站流量增加后,我们发现有时套接字会出现这种错误:错误提供静态/socket.io.js而我们丢失了套接字连接。
点击几次后,F5 socket.io已连接。 我们有100-150个用户/选择它并不多,但我们仍然在socket.io中遇到性能问题。
我们阅读了很多关于nginx,fpm性能的文章,但没有任何帮助。
这很棘手,因为任何其他文件(js,css等)永远不会得到500 Bad gateway,只有socket / socket.io.js才能得到它。
如果有人有类似的问题?
我对socket.io的nginx配置如下所示:
server {
listen 443 ssl;
ssl_certificate /etc/ssl/ao-certs/socket/bundle.pem;
ssl_certificate_key /etc/ssl/ao-certs/socket/private.key;
ssl_ciphers RC4:HIGH:!aNULL:!MD5:!ADH:!kEDH;
ssl_prefer_server_ciphers on;
server_name socket.customericare.com;
location / {
proxy_pass http://127.0.0.1:8081; #this is the ip:port where your node app runs root /var/www/yoursitename; expires 30d; #uncomment this is you want to name an index file: #index index.php index.html;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
access_log off;
}
}
nginx app config:
server {
listen 443 ssl;
ssl_certificate /etc/ssl/ao-certs/app/bundle.pem;
sssl_certificate_key /etc/ssl/ao-certs/app/private.key;
server_name app.customericare.com;
index index.php index.html index.htm;
access_log off;
location / {
root /var/www/vhosts/app.customericare.com/;
index index.php index.html;
try_files $uri $uri/ @rewrite;
}
# static file 404's aren't logged and expires header is set to maximum age
location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
root /var/www/vhosts/app.customericare.com/;
access_log off;
expires max;
try_files $uri @rewrite;
}
location ~ \.php$ {
# By all means use a different server for the fcgi processes if you need to
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_param SCRIPT_FILENAME /var/www/vhosts/app.customericare.com/$fastcgi_script_name;
fastcgi_param SERVER_NAME app.customericare.com;
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
}
来自nginx的error.log:
2014/08/18 15:15:03 [error] 30627#0: *84775 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: _, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost"
2014/08/18 15:15:36 [error] 30624#0: *86344 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 178.219.114.213, server: _, request: "GET /api/history?key=d67d8ab4f4c10bf22aa353e27879133c&callback=jQuery1910025671478084960175_1408367787961&url=%2F128202%2CPlytka-scienna-Ashen-1-dekor-298x598-Tubadzin.html&referer=http%253A%252F%252Fwww.google.pl%252Faclk%253Fsa%253Dl%2526ai%253DCxtBPmPzxU761JoHs7QbC2oKoCdG4s9wG0f_o2oIBuYyOqvABCAYQBCC2VCgIUJLyycf4_____wFg6fS7hcAaoAGn9ZHdA8gBB6kCViPo5gVvlT6qBCZP0CEZtRELzRwscpJrLVykYG116t-ZOVLU2JZhK303WoihaBRHCoAFkE7ABQWgBiaAB8GK7iKQBwOoB6a-G-ASs-i62Ye6x6L-AQ%2526sig%253DAOD64_247fMXEARqfH0TFZPOKDesc7km8w%2526ctype%253D5%2526rct%253Dj%2526q%253D%2526ved%253D0CKUBELsX%2526adurl%253Dhttp%253A%252F%252Fclickserve.dartsearch.net%252Flink%252Fclick%25253Flid%25253D93700004546857158%252526ds_s_kwgid%25253D58700000218636004%252526ds_e_adid%25253D34995694433%252526ds_e_source%25253Dpla%252526ds_e_product_target_id%25253D64512820793%252526ds_e_product_id%25253D128202%252526ds_url_v%25253D2%252526ds_dest_url%25253Dhttp%253A%252F%252Fnexterio.pl%252F128202%252CPlytka-scienna-Ashen-1-dekor-298x598-Tubadzin.html&res=1366x768&domain=nexterio.pl&_=1408367787963 HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "app.customericare.com", referrer: "http://nexterio.pl/128202,Plytka-scienna-Ashen-1-dekor-298x598-Tubadzin.html?gclid=CP-0j-zynMACFabLtAod5VsAMQ"
2014/08/18 15:15:36 [error] 30624#0: *86486 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 178.219.114.213, server: _, request: "GET /ajax/initplugin/?callback=jQuery1910025671478084960175_1408367787964&apiKey=d67d8ab4f4c10bf22aa353e27879133c§ionId=&userId=843579&companyIds=040206775abd329f334c1b67a0471423&_=1408367787965 HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "app.customericare.com", referrer: "http://nexterio.pl/128202,Plytka-scienna-Ashen-1-dekor-298x598-Tubadzin.html?gclid=CP-0j-zynMACFabLtAod5VsAMQ"
2014/08/18 15:15:36 [error] 30624#0: *84325 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 83.8.230.170, server: _, request: "GET /api/check-cookie?key=d67d8ab4f4c10bf22aa353e27879133c&callback=jQuery19103423224048516038_1408367780109&_=1408367780110 HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "app.customericare.com", referrer: "http://nexterio.pl/16603,16599,16590,Utrzymanie-czystosci-i-przechowywanie_Kosze-na-smieci.html"
2014/08/18 15:15:36 [error] 30623#0: *86466 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 77.252.56.2, server: _, request: "GET /api?key=d67d8ab4f4c10bf22aa353e27879133c HTTP/1.0", upstream: "fastcgi://127.0.0.1:9000", host: "app.customericare.com", referrer: "http://nexterio.pl/15354,15337,15337,Elektronarzedzia_Wiertarko-wkretarki.html?utm_source=wp&utm_medium=baner_branding&utm_campaign=Portale&utm_term=gif&utm_content=wiertarko-wkretarki"
2014/08/18 15:15:36 [error] 30624#0: *85652 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 78.8.39.41, server: _, request: "GET /api/check-cookie?key=d67d8ab4f4c10bf22aa353e27879133c&callback=jQuery19108185782760291924_1408367791167&_=1408367791168 HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "app.customericare.com", referrer: "http://nexterio.pl/16392,16355,16355,Oswietlenie-wewnetrzne_Lampy-wiszace.html?filtry=&utm_source=interia&utm_medium=baner_branding&utm_campaign=Portale&utm_term=130x95&utm_content=lampy_wew&s=2"
2014/08/18 15:19:02 [error] 30624#0: *96228 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 83.6.7.75, server: socket.customericare.com, request: "GET /socket.io/1/websocket/oYFh4Kf9B4wRgNwUBZ25 HTTP/1.1", upstream: "http://127.0.0.1:8081/socket.io/1/websocket/oYFh4Kf9B4wRgNwUBZ25", host: "socket.customericare.com"
2014/08/18 15:19:02 [error] 30624#0: *96232 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 212.160.172.85, server: socket.customericare.com, request: "GET /socket.io/1/websocket/ABhF76o3llLT7bZ7BZ27 HTTP/1.1", upstream: "http://127.0.0.1:8081/socket.io/1/websocket/ABhF76o3llLT7bZ7BZ27", host: "socket.customericare.com"
2014/08/18 15:19:02 [error] 30626#0: *93339 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 213.156.124.172, server: socket.customericare.com, request: "GET /socket.io/socket.io.js HTTP/1.1", upstream: "http://127.0.0.1:8081/socket.io/socket.io.js", host: "socket.customericare.com", referrer: "http://www.expander.pl/serwis-ekonomiczny/produkty/KwartetGwiazd2II.html"
2014/08/18 15:19:02 [error] 30627#0: *96237 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 84.10.9.214, server: socket.customericare.com, request: "GET /socket.io/1//hIWIh5ovD9hdQtT2BZ1e/?disconnect=1 HTTP/1.1", upstream: "http://127.0.0.1:8081/socket.io/1//hIWIh5ovD9hdQtT2BZ1e/?disconnect=1", host: "socket.customericare.com", referrer: "http://nexterio.pl/16392,16355,16355,Oswietlenie-wewnetrzne_Lampy-wiszace.html?utm_source=interia&utm_medium=baner_branding&utm_campaign=Portale&utm_term=130x95&utm_content=lampy_wew"
2014/08/18 15:20:02 [error] 30624#0: *99046 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: _, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost"
2014/08/18 15:25:03 [error] 30626#0: *111928 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: _, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost"
2014/08/18 15:30:02 [error] 30623#0: *124459 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: _, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost"
2014/08/18 15:32:28 [error] 30627#0: *125573 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 78.8.2.57, server: socket.customericare.com, request: "GET /socket.io/socket.io.js HTTP/1.1", upstream: "http://127.0.0.1:8081/socket.io/socket.io.js", host: "socket.customericare.com", referrer: "http://nexterio.pl/16392,16355,16355,Oswietlenie-wewnetrzne_Lampy-wiszace.html?filtry=&utm_source=interia&utm_medium=baner_branding&utm_campaign=Portale&utm_term=130x95&utm_content=lampy_wew&s=7"
2014/08/18 15:33:11 [error] 30626#0: *132144 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 83.16.160.242, server: socket.customericare.com, request: "GET /socket.io/socket.io.js HTTP/1.1", upstream: "http://127.0.0.1:8081/socket.io/socket.io.js", host: "socket.customericare.com", referrer: "http://nexterio.pl/133737,Lampa-wiszaca-wielopunktowa-Bazylea-6xG9-40W-Light-Prestige.html"
2014/08/18 15:34:05 [error] 30627#0: *134505 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 178.36.180.126, server: socket.customericare.com, request: "GET /socket.io/socket.io.js HTTP/1.1", upstream: "http://127.0.0.1:8081/socket.io/socket.io.js", host: "socket.customericare.com", referrer: "http://nexterio.pl/133763,Firana-Benita-W07900-200x180-Wisan.html?utm_source=domodi&utm_medium=cpc&utm_content=link&utm_campaign=homebook&utm_term=Firany"
2014/08/18 15:34:05 [error] 30627#0: *125730 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 78.88.56.33, server: socket.customericare.com, request: "GET /socket.io/1//3gIJTOfkZO32R41ZBa4i/?disconnect=1 HTTP/1.1", upstream: "http://127.0.0.1:8081/socket.io/1//3gIJTOfkZO32R41ZBa4i/?disconnect=1", host: "socket.customericare.com", referrer: "http://nexterio.pl/16388,16386,16355,Oswietlenie-wewnetrzne_Oprawy-punktowe-schodowe.html?params=f4:14374106&cid=16388"
2014/08/18 15:34:05 [error] 30624#0: *134526 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 83.21.82.46, server: socket.customericare.com, request: "GET /socket.io/1/websocket/I-xxmL26tJWjxv9bBa4w HTTP/1.1", upstream: "http://127.0.0.1:8081/socket.io/1/websocket/I-xxmL26tJWjxv9bBa4w", host: "socket.customericare.com"
2014/08/18 15:35:03 [error] 30623#0: *137234 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: _, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost"
2014/08/18 15:36:35 [error] 30623#0: *140441 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 80.94.30.44, server: socket.customericare.com, request: "GET /socket.io/socket.io.js HTTP/1.1", upstream: "http://127.0.0.1:8081/socket.io/socket.io.js", host: "socket.customericare.com", referrer: "http://nexterio.pl/?"
2014/08/18 15:36:35 [error] 30627#0: *140440 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 84.10.14.42, server: socket.customericare.com, request: "GET /socket.io/socket.io.js HTTP/1.1", upstream: "http://127.0.0.1:8081/socket.io/socket.io.js", host: "socket.customericare.com", referrer: "http://nexterio.pl/szukaj.php?fraza=przej%C5%9Bci%C3%B3ka+e27+e14&bnh=&search=&clear=1"
服务器负载:
CPU: ~15-40%
Mem: ~2000/8000 MB
Swap: ~5/3904 MB
PM2 monit:
CPU process: ~7-20%
Mem: ~136 MB
在node.js(pm2)中,当我重新启动进程时,我有大约20-30MB的内存使用量。 几秒后,它增加到~130MB。