您当前的位置: 首页 >  nginx

dawn

暂无认证

  • 4浏览

    0关注

    204博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

nginx的动静分离

dawn 发布时间:2022-07-06 11:08:03 ,浏览量:4

  使用nginx的动静分离可以让多个不同的Web服务器各司其职,涉及Servlet、Jsp页面处理交给Tomcat处理,涉及PHP页面处理交给apache,asp.net页面交个IIS,py的页面交给py的web服务器处理,而静态页面都交给nginx处理。

  servlet的处理可以加后缀,比如后缀为.do,这样标识方便nginx处理。

  修改conf下的nginx.conf配置:

http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       9001;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   G:/nginx/html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # PHP===》PHP文件的处理
        location ~ \.php$ {
            proxy_pass   http://127.0.0.1:80;
        }

        #Java===》servlet和JSP页面的处理
        location ~ \.(jsp|do)$ {
            proxy_pass   http://127.0.0.1:9019;
        }
    }
}

  启动Apache、Tomcat、nginx,其中Apache运行于80端口,Tomcat运行于9019端口,nginx运行于9001端口。

  编写测试页面:



	
		
		获取Java数据
		
	
		
	
		获取Java-Servlet数据
		
获取PHP数据
function GetData1(){ $.ajax({ url: 'http://127.0.0.1:9001/JavaWeb2022/servletdemo.do', //请求的url地址 dataType: "text", async: true, //请求是否异步,默认true异步,这是ajax的特性 data:{ name:"QWE", age:13 }, type: "POST", //请求的方式 beforeSend:function(){}, //请求前的处理 success: function(data) { // 请求签的处理 console.log(data); document.getElementById("demo1").innerHTML = document.getElementById("demo1").innerHTML + data+""; } }); } function GetData2(){ $.ajax({ url: 'http://127.0.0.1:9001/PHP2021/test/test.php', //请求的url地址 dataType: "text", async: true, //请求是否异步,默认true异步,这是ajax的特性 data:{ name:"QWE", age:13 }, type: "POST", //请求的方式 beforeSend:function(){}, //请求前的处理 success: function(data) { // 请求签的处理 console.log(data); document.getElementById("demo2").innerHTML = document.getElementById("demo2").innerHTML + data+""; } }); }

  运行:

 

关注
打赏
1664252102
查看更多评论
立即登录/注册

微信扫码登录

0.2957s