Detailed explanation of solving the problem of cross-domain access of nginx/apache static resources

Detailed explanation of solving the problem of cross-domain access of nginx/apache static resources

1. Apache static resource cross-domain access

Find the Apache configuration file httpd.conf

Find this line

#LoadModule headers_module modules/mod_headers.so

Remove the # comment character

LoadModule headers_module modules/mod_headers.so

The purpose is to enable the Apache header information custom module

Add a new header to the standalone host configuration file

Header set Access-Control-Allow-Origin *

For example:

<VirtualHost *:88>
 ServerAdmin [email protected]
 DocumentRoot "****************"
 ServerName www.jb51.com
 Header set Access-Control-Allow-Origin *

 ErrorLog "***********"
 CustomLog "****************************" common
<Directory "**************">
 SetOutputFilter DEFLATE
 Options FollowSymLinks ExecCGI
 Require all granted
 AllowOverride All
 Order allow, deny
 Allow from all
 DirectoryIndex index.html index.php
</Directory>
</VirtualHost>
ApacheCopy

This means adding a header when accessing resources on this domain name.

Restart apache

service httpd restart

2. nginx static resources allow cross-domain access

Similarly, find the corresponding domain name configuration file

Add configuration in the server module:

add_header 'Access-Control-Allow-Origin' '*';

example:

server {
    listen 80;
    add_header 'Access-Control-Allow-Origin' '*';
    location /Roboto/ {
      root /home/images;
      autoindex on;
    }
  }

nginx reload

./nginx -s reload

After configuring through the above method, there is no problem in accessing static resources across domains again

The above is the solution to allow cross-domain access to nginx/apache static resources

You may also be interested in:
  • How to use nginx to access local static resources on Linux server
  • Detailed explanation of Nginx + Tomcat to separate requests for dynamic data and static resources
  • Detailed explanation of simple configuration of nginx static resource server
  • Nginx implements reverse proxy example of static resources
  • Use nginx-http-concat module to merge static resource files in nginx
  • How to publish static resources in nginx

<<:  Summary of Binlog usage of MySQL database (must read)

>>:  JavaScript uses setTimeout to achieve countdown effect

Recommend

Summary of Mysql slow query operations

Mysql slow query explanation The MySQL slow query...

MySQL 8.0.11 Installation Tutorial under Windows

This article records the installation tutorial of...

A must-read career plan for web design practitioners

Original article, please indicate the author and ...

MySQL 8.0.15 version installation tutorial connect to Navicat.list

The pitfalls 1. Many tutorials on the Internet wr...

Specific use of MySQL global locks and table-level locks

Table of contents Preface Global Lock Table lock ...

HTML Tutorial: DOCTYPE Abbreviation

When writing HTML code, the first line should be ...

How to reset the root password in Linux mysql-5.6

1. Check whether the MySQL service is started. If...

React+Amap obtains latitude and longitude in real time and locates the address

Table of contents 1. Initialize the map 2. Map Po...

Method of implementing recursive components based on Vue technology

describe This article introduces a method to impl...

MySQL Series 13 MySQL Replication

Table of contents 1. MySQL replication related co...

MySQL aggregate function sorting

Table of contents MySQL result sorting - Aggregat...

Detailed steps for porting busybox to build a minimal root file system

Busybox: A Swiss Army knife filled with small com...