为了账号安全,请及时绑定邮箱和手机立即绑定

nginx反向代理到本机nodejs应用时速度很慢

nginx反向代理到本机nodejs应用时速度很慢

富国沪深 2019-03-29 22:11:14
我用nodejs搭了一个网站,但是同网的其他的机器无法访问,我上网查,有人说需要一个web服务器发布出来,所以我本机又搭了nginx进行反向代理到我nodejs上,但是很慢。每次第一次访问都得等好长时间。但是直接访问nodejs的端口就很快。项目很小,不应该,所以我感觉是反向代理哪里设置的不对。求解?#usernobody;worker_processes2;#error_loglogs/error.log;#error_loglogs/error.lognotice;error_loglogs/error.loginfo;#pidlogs/nginx.pid;events{worker_connections65535;}http{includemime.types;default_typeapplication/octet-stream;server_names_hash_bucket_size128;#增加client_header_buffer_size32k;#增加large_client_header_buffers432k;#增加client_max_body_size300m;#增加tcp_nopushon;#修改为onkeepalive_timeout60;#修改为60tcp_nodelayon;#增加server_tokensoff;#增加,不显示nginx版本信息gzipon;#修改为ongzip_min_length1k;#增加gzip_buffers416k;#增加gzip_http_version1.1;#增加gzip_comp_level2;#增加gzip_typestext/plainapplication/x-javascripttext/cssapplication/xml;#增加gzip_varyon;#增加#log_formatmain'$remote_addr-$remote_user[$time_local]"$request"'#'$status$body_bytes_sent"$http_referer"'#'"$http_user_agent""$http_x_forwarded_for"';#access_loglogs/access.logmain;sendfileon;#tcp_nopushon;#keepalive_timeout0;#keepalive_timeout65;#gzipon;map$http_upgrade$connection_upgrade{defaultupgrade;''close;}server{listen9080;server_namelocalhost;#charsetkoi8-r;#access_loglogs/host.access.logmain;#location/{#roothtml;#indexindex.htmlindex.htm;#}location/{proxy_passhttp://localhost:8080;#nodejsproxy_set_headerX-Real-IP$remote_addr;proxy_set_headerHost$host;proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;proxy_http_version1.1;proxy_set_headerUpgrade$http_upgrade;proxy_set_headerConnection"upgrade";#timeoutsettingsproxy_connect_timeout159s;proxy_send_timeout600;proxy_read_timeout600;proxy_buffer_size64k;proxy_buffers1632k;proxy_busy_buffers_size64k;proxy_temp_file_write_size64k;proxy_pass_headerSet-Cookie;proxy_redirectoff;proxy_hide_headerVary;proxy_set_headerAccept-Encoding'';proxy_ignore_headersCache-ControlExpires;proxy_set_headerReferer$http_referer;proxy_set_headerHost$host;proxy_set_headerCookie$http_cookie;proxy_set_headerX-Real-IP$remote_addr;proxy_set_headerX-Forwarded-Host$host;proxy_set_headerX-Forwarded-Server$host;proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;}#error_page404/404.html;#redirectservererrorpagestothestaticpage/50x.html#error_page500502503504/50x.html;location=/50x.html{roothtml;}#proxythePHPscriptstoApachelisteningon127.0.0.1:80##location~\.php${#proxy_passhttp://127.0.0.1;#}#passthePHPscriptstoFastCGIserverlisteningon127.0.0.1:9000##location~\.php${#roothtml;#fastcgi_pass127.0.0.1:9000;#fastcgi_indexindex.php;#fastcgi_paramSCRIPT_FILENAME/scripts$fastcgi_script_name;#includefastcgi_params;#}#denyaccessto.htaccessfiles,ifApache'sdocumentroot#concurswithnginx'sone##location~/\.ht{#denyall;#}}#anothervirtualhostusingmixofIP-,name-,andport-basedconfiguration##server{#listen8000;#listensomename:8080;#server_namesomenamealiasanother.alias;#location/{#roothtml;#indexindex.htmlindex.htm;#}#}#HTTPSserver##server{#listen443;#server_namelocalhost;#sslon;#ssl_certificatecert.pem;#ssl_certificate_keycert.key;#ssl_session_timeout5m;#ssl_protocolsSSLv2SSLv3TLSv1;#ssl_ciphersHIGH:!aNULL:!MD5;#ssl_prefer_server_cipherson;#location/{#roothtml;#indexindex.htmlindex.htm;#}#}}
查看完整描述

2 回答

?
慕莱坞森

TA贡献1810条经验 获得超4个赞

你用nginx设置了这么多HTTPheader做什么?
只需要这三个,其他的删掉:
proxy_set_headerX-Real-IP$remote_addr;
proxy_set_headerHost$host;
proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;
把这一段也删掉:
map$http_upgrade$connection_upgrade{
defaultupgrade;
''close;
}
很可能是你设了upgrade的header造成的问题。
                            
查看完整回答
反对 回复 2019-03-29
?
Qyouu

TA贡献1786条经验 获得超11个赞

在server下增加下面的配置项,看看是否有效果
ip_hash;
                            
查看完整回答
反对 回复 2019-03-29
  • 2 回答
  • 0 关注
  • 590 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信