1.Niginx主配置文件参数详解a.上面博客说了在Linux中安装nginx。博文地址为:http://www.cnblogs.com/hanyinglong/p/5102141.html b.当Nginx安装完毕后,会有相应的安装目录,安装目录里的nginx.confg为nginx的主配置文件,nginx主配置文件分为4部分,main(全局配置)、server(主机配置)、upstream(负载均衡服务器设置)以及location(URL匹配特定位置的设置),这四者的关系是:server继承main,location继承server,upstream既不会继承其它设置也不会被继承。 c.Nginx是一个代理服务器,一般情况下,网站是不能部署在Nginx下的,比如用Java开发的JavaWeb程序,我们部署在tomcat下,然后使用Nginx代理将网址指向tomcat即可。2.Nginx.conf配置文件详细说明(附备注)#kencery注释说明Nginx文件#时间:2016-1-19#学习内容,只是来自互联网,有版权问题请联系我删除。########Nginx的main(全局配置)文件#指定nginx运行的用户及用户组,默认为nobody#usernobody;#开启的线程数,一般跟逻辑CPU核数一致worker_processes1;#定位全局错误日志文件,级别以notice显示,还有debug,info,warn,error,crit模式,debug输出最多,crir输出最少,根据实际环境而定#error_loglogs/error.log;#error_loglogs/error.lognotice;#error_loglogs/error.loginfo;#指定进程id的存储文件位置#pidlogs/nginx.pid;#指定一个nginx进程打开的最多文件描述符数目,受系统进程的最大打开文件数量限制#worker_rlimit_nofile65535events{#设置工作模式为epoll,除此之外还有select,poll,kqueue,rtsig和/dev/poll模式#useepoll;#定义每个进程的最大连接数,受系统进程的最大打开文件数量限制。worker_connections1024;}#######Nginx的Http服务器配置,Gzip配置http{#主模块指令,实现对配置文件所包含的文件的设定,可以减少主配置文件的复杂度,DNS主配置文件中的zonerfc1912,acl基本上都是用include语句。includemime.types;#核心模块指令,智力默认设置为二进制流,也就是当文件类型未定义时使用这种方式default_typeapplication/octet-stream;#下面代码为日志格式的设定,main为日志格式的名称,可自行设置,后面引用#log_formatmain'$remote_addr-$remote_user[$time_local]"$request"'#'$status$body_bytes_sent"$http_referer"'#'"$http_user_agent""$http_x_forwarded_for"';#引用日志main#access_loglogs/access.logmain;#设置允许客户端请求的最大的单个文件字节数#client_max_body_size20M;#指定来自客户端请求头的headebuffer大小#client_header_buffer_size32k;#指定连接请求试图写入缓存文件的目录路径#client_body_temp_path/dev/shm/client_body_temp;#指定客户端请求中较大的消息头的缓存最大数量和大小,目前设置为4个32KB#largeclient_header_buffers432k;#开启高效文件传输模式sendfileon;#开启防止网络阻塞#tcp_nopushon;#开启防止网络阻塞#tcp_nodelayon;#设置客户端连接保存活动的超时时间#keepalive_timeout0;keepalive_timeout65;#设置客户端请求读取超时时间#client_header_timeout10;#设置客户端请求主体读取超时时间#client_body_timeout10;#用于设置相应客户端的超时时间#send_timeout####HttpGZip模块配置#httpGzipmodules#开启gzip压缩#gzipon;#设置允许压缩的页面最小字节数#gzip_min_length1k;#申请4个单位为16K的内存作为压缩结果流缓存#gzip_buffers416k;#设置识别http协议的版本,默认为1.1#gzip_http_version1.1;#指定gzip压缩比,1-9数字越小,压缩比越小,速度越快#gzip_comp_level2;#指定压缩的类型#gzip_typestext/plainapplication/x-javascripttext/cssapplication/xml;#让前端的缓存服务器进过gzip压缩的页面#gzip_varyon;#########Nginx的server虚拟主机配置server{#监听端口为80listen80;#设置主机域名server_namelocalhost;#设置访问的语言编码#charsetkoi8-r;#设置虚拟主机访问日志的存放路径及日志的格式为main#access_loglogs/host.access.logmain;#设置虚拟主机的基本信息location/{#设置虚拟主机的网站根目录roothtml;#设置虚拟主机默认访问的网页indexindex.htmlindex.htm;}#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{#listen443ssl;#server_namelocalhost;#ssl_certificatecert.pem;#ssl_certificate_keycert.key;#ssl_session_cacheshared:SSL:1m;#ssl_session_timeout5m;#ssl_ciphersHIGH:!aNULL:!MD5;#ssl_prefer_server_cipherson;#location/{#roothtml;#indexindex.htmlindex.htm;#}#}}3.Nginx代理网站a.我在tomcat下部署了一个javaweb项目,tomcat安装的服务器IP为:192.168.37.136,部署的项目在tomcat下的访问地址为:http://192.168.37.136:8080/lywh/ b.我在IP为192.168.37.133的服务器下面安装成功了Nginx。 c.那怎么样将tomcat下部署的网站使用Nginx代理呢?,修改Nginx的配置文件,修改命令:vim/usr/local/nginx/conf/nginx.conf#usernobody;worker_processes1;#error_loglogs/error.log;#error_loglogs/error.lognotice;#error_loglogs/error.loginfo;#pidlogs/nginx.pid;events{worker_connections1024;}http{includemime.types;default_typeapplication/octet-stream;#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;#配置tomcat的IP地址和访问端口upstreamgw{server192.168.37.136:8080weight=1;}server{listen80;server_namelocalhost;#charsetkoi8-r;#access_loglogs/host.access.logmain;location/{roothtml;indexindex.htmlindex.htm;}#Nginx代理配置location/lywh{proxy_passhttp://gw/lywh;}location/sapi{proxy_passhttp://gw/shopappapi;}location/cas{proxy_passhttp://gw/cas-server-webapp-4.0.0/login;}location/doc{proxy_passhttp://gw/docs;}#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{#listen443ssl;#server_namelocalhost;#ssl_certificatecert.pem;#ssl_certificate_keycert.key;#ssl_session_cacheshared:SSL:1m;#ssl_session_timeout5m;#ssl_ciphersHIGH:!aNULL:!MD5;#ssl_prefer_server_cipherson;#location/{#roothtml;#indexindex.htmlindex.htm;#}#}}
getUrlKey:function(name){//获取url参数returndecodeURIComponent((newRegExp('[?|&]'+name+'='+'([^&;]+?)(&|#|;|$)').exec(location.href)||[,""])[1].replace(/\+/g,'%20'))||null;}functiongetCodeApi(state){//获取codeleturlNow=encodeURIComponent(window.location.href);letscope='snsapi_base';//snsapi_userinfo//静默授权用户无感知letappid='wx4cc5d5c123123123';leturl=`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${urlNow}&response_type=code&scope=${scope}&state=${state}#wechat_redirect`;window.location.replace(url);}created(){letcode=getUrlKey("code");if(code){//调用接口获取openId参考文档https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140842getOpenIdApi(code).then(res=>{letopenId=res.openId;window.location.replace("/#/login");}).catch(res=>{window.location.replace("/#/login");})}else{getCodeApi("123");}}