猿问

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

我用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;#修改为on
keepalive_timeout60;#修改为60
tcp_nodelayon;#增加
server_tokensoff;#增加,不显示nginx版本信息
gzipon;#修改为on
gzip_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;#nodejs
proxy_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";
#timeoutsettings
proxy_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;
#}
#}
}
富国沪深
浏览 594回答 2
2回答

慕莱坞森

你用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造成的问题。

Qyouu

在server下增加下面的配置项,看看是否有效果ip_hash;
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答