由于使用docker配置Nginx比较方便,所以博主就使用docker做为容器配置下
第一步、配置docker-compose.yml文件
version: '
services:
nginx:
restart: always
image: nginx
container_name: nginx-
ports:
- :
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/
说明下上面的代码的几个重要部分
第二步、配置nginx.conf文件
nginx.fonf
user nginx;
worker_processes ; events {
worker_connections ;
} http { include mime.types; default_type application/octet-stream; keepalive_timeout ; server {
listen ;
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;
}
}
}
说明下上面部分代码的含义