Help Articles
search
Nginx cross-domain settings
Category: Website building help
author: Tom
Time: 2025-07-06
Read: 9

Cross-origin refers to the behavior of browsers restricting web scripts from making requests to servers with different origins (different protocols, domain names, or ports) for security reasons. This restriction is caused by the browser's ​Same-Origin Policy​​.


Solve cross-domain

 # General configuration of static resources (pictures, multimedia, fonts, JS, CSS, etc.)
location ~* \.(jpg|jpeg|png|gif|bmp|webp|svg|ico|mp4|webm|ogg|js|css|woff|woff2|ttf|eot)$
{
# Allow cross-domain access for all domain names
add_header Access-Control-Allow-Origin "*" always;
add_header Access-Control-Allow-Methods "GET" always;
add_header Access-Control-Allow-Headers "*" always;
add_header Access-Control-Max-Age 86400 always;
# Cache settings
expires 365d;
add_header Cache-Control "public, immutable, max-age=31536000, s-maxage=31536000" always;

# Security Enhanced Header
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
try_files $uri =404;
access_log off;
error_log /dev/null;
log_not_found off;
}

The above settings are for the cdn side that cannot set the http response header. If the cdn side can set the response header, just set it directly! Just get the request!


Refresh related cross-domain links

If your CDN link has a cross-domain problem, please refresh the link after setting up the cross-domain configuration on the source site. After refreshing, the link you set can be accessed normally.

上一篇:What should I do if the Windows system suddenly has no sound?
下一篇:How to set up automatic synchronization of server time in Baota panel
Customer Service
Pre sales consultation
在线客服
after-sale service
24/7 operation and maintenance
运维客服
Feedback
Complaints and Suggestions
投诉与建议
置顶