docker-compose.yml

  1. version: '3.7'
  2. services:
  3. nginx:
  4. restart: always
  5. image: nginx:latest
  6. container_name: nginx
  7. ports:
  8. - 8080:8080
  9. volumes:
  10. - ./conf/nginx.conf:/etc/nginx/nginx.conf
  11. - ./wwwroot:/usr/share/nginx/wwwroot

配置

/usr/loacl/docker/nginx/conf/下创建nginx.conf文件

  1. # 核心数量
  2. worker_processes 1;
  3. events {
  4. # 连接数
  5. worker_connections 1024;
  6. }
  7. # http代理
  8. http {
  9. include mime.types;
  10. default_type application/octet-stream;
  11. sendfile on;
  12. keepalive_timeout 65;
  13. server {
  14. listen 8080;
  15. server_name www.hzlim.cn;
  16. location / {
  17. add_header Access-Control-Allow-Origin *;
  18. add_header Access-Control-Allow-Headers X-Requested-With;
  19. add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,PATCH,OPTIONS;
  20. root /usr/share/nginx/wwwroot;
  21. index index.html index.htm;
  22. }
  23. }
  24. }