Apache + tomcat + js + css implement separation of cross-origin

Source: Internet
Author: User
Tags subdomain name
Combined with the previous commit. If you use different domain names, you will encounter cross-origin requests...

Combine the previous http://www.2cto.com/ OS /201511/112841.html, and continue the resources of the separation sites to the different sites

 

 

If a java site uses a tomcat server, the css, images, and js of the site must be separated. If you use different domain names, you will encounter cross-domain situations. Therefore, apache Proxy is used for separation.

 

 

Put all css, images, and js resources

 

Src.test.com/css /......

 

Src.test.com/images /......

 

Src.test.com/js /......

 

 

Java site tomcat server access method

 

Ajp: // 127.0.0.1: 8009/

It is actually http: // 127.0.0.1: 8080/

 

 

 

Apache httpd. conf configuration

 

ServerName mnr.test.com

RewriteEngine on

RewriteRule ^/(. *) ajp: // www.2cto.com/sub/$1 [P]

 

Then access the site through http://sub.test.com

 

 

Because css, images, and js resources are independent domain names, they may be on other servers, but they must be called using the same domain name in the subdomain name to avoid cross-origin requests.

 

ServerName mnr.test.com

RewriteEngine on

ProxyPass/js/http://src.test.com/js/

ProxyPass/css/http://src.test.com/css/

ProxyPass/images/http://src.test.com/images/

RewriteRule ((?! /(Js) | (css) | (img)/) ^. * $) ajp: // 127.0.0.1: 8009/sub/$1 [P]

Restart apache

 

 

Call ING:

Sub.test.com/css src.test.com/css /......

 

Sub.test.com/images src.test.com/images /......

 

Sub.test.com/js src.test.com/js /......

 

All sub.test.com resources are resources under the tomcat directory.

 

Author bayaci

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.