Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to use Nginx to configure the CDN server under Linux

Shulou Source: shulou.com Published: 2022-06-01 03:42:15 09月19日 Update

In this issue, the editor will bring you about how to use Nginx to configure the CDN server under Linux. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.

Because it is convenient to use docker to configure Nginx, bloggers use docker as a container to configure

The first step, Configure the docker-compose.yml file version:'3 services: nginx: restart: always image: nginx container_name: nginx-1 ports:-80:80 volumes:-/ usr/local/application/nginx/conf/nginx.conf:/etc/nginx/nginx.conf-/ usr/local/application/nginx/logs/:/var/log/nginx/ -/ usr/local/application/nginx/data/:/var/share/nginx/html/-/ usr/local/application/nginx/cdn/:/usr/share/nginx/html/

Explain several important parts of the above code

First of all, there is the value of the node volumes: the mapping of the first configuration file of    is followed by the host, followed by the second log mapping of the container   , the third data file mapping   , the mapping of the fourth cdn of   , the second step of configuring the nginx.conf file.

   nginx.fonf

User nginx;worker_processes 1; events {worker_connections 1024;} http {include mime.types; default_type application/octet-stream; keepalive_timeout 65; server {listen 80; server_name 192.168.157.128; location / {root / usr/share/nginx/html; index index.html index.htm Add_header 'Access-Control-Allow-Origin'' *'; add_header 'Access-Control-Allow-Credentials'' true'; add_header 'Access-Control-Allow-Methods'' GET, PUT, POST, DELETE, OPTIONS';} location ~ *. (eot | ttf | woff | woff2 | svg | otf) ${add_header Access-Control-Allow-Origin *; root / usr/share/nginx/html }}}

Explain the meaning of the above code

The first place: the value of root represents the value in the container because it is mapped to the conf file of the container. The second place: three add_header   , the first represents the domain allowed to be accessed, * indicates unified configuration, for security, the custom domain name    is recommended, the second indicates whether to take Cookie   , and the third indicates the allowed request method, GET and OPTIONS must vote for a third party: the values of include and default_type indicate the content of the requested Content-Type, if not set. Css files and js files that use CDN in html will report an error in the browser and do not understand the COntent-Type type. The above is the editor for you to share how to use Nginx to do the configuration under the CDN server under Linux. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Tags: Configuration file container three content place server service code that is part analysis important security professional two small and medium medium report rich content meaning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Tech Info Huawei Docker MySQL