nginx.confg

  1. # For more information on configuration, see:
  2. # * Official English Documentation: http://nginx.org/en/docs/
  3. # * Official Russian Documentation: http://nginx.org/ru/docs/
  4. user nginx;
  5. worker_processes auto;
  6. error_log /var/log/nginx/error.log;
  7. pid /run/nginx.pid;
  8. # Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
  9. include /usr/share/nginx/modules/*.conf;
  10. events {
  11. worker_connections 1024;
  12. }
  13. http {
  14. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  15. '$status $body_bytes_sent "$http_referer" '
  16. '"$http_user_agent" "$http_x_forwarded_for"';
  17. access_log /var/log/nginx/access.log main;
  18. sendfile on;
  19. tcp_nopush on;
  20. tcp_nodelay on;
  21. keepalive_timeout 65;
  22. types_hash_max_size 2048;
  23. include /etc/nginx/mime.types;
  24. default_type application/octet-stream;
  25. include /etc/nginx/conf.d/*.conf
  26. }

confg.d文件夹下example.conf

  1. server {
  2. listen 80;
  3. server_name labour.bringbuys.com;
  4. access_log labour.access.log;
  5. gzip on; // 开启gzip压缩优化,前端vue-cli用webpack配置build时,开启productionGzip为true。
  6. gzip_min_length 1k;
  7. gzip_buffers 4 8k;
  8. gzip_http_version 1.1;
  9. gzip_types text/plain application/javascript application/x-javascript text/javascript text/xml text/css;
  10. location /d/resource {
  11. alias /data/download/files;
  12. autoindex off;
  13. autoindex_exact_size off;
  14. }
  15. location / {
  16. proxy_connect_timeout 300s;
  17. proxy_send_timeout 300s;
  18. proxy_read_timeout 300s;
  19. add_header Cache-Control 'no-cache,max-age=0';
  20. root /data/src/labour-system/dist;
  21. try_files $uri $uri/ /index.html last;
  22. index index.html index.html;
  23. gzip_static on;
  24. }
  25. location /api/ {
  26. proxy_connect_timeout 300s;
  27. proxy_send_timeout 300s;
  28. proxy_read_timeout 300s;
  29. proxy_http_version 1.1;
  30. proxy_pass http://api.labour.bringbuys.com/;
  31. proxy_set_header Host "api.labour.bringbuys.com";
  32. proxy_set_header X-Real-IP $remote_addr;
  33. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  34. client_max_body_size 100m;
  35. access_log on;
  36. #支持跨域访问的问题
  37. add_header Access-Control-Allow-Origin *;
  38. add_header Access-Control-Allow-Headers X-Requested-With;
  39. add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
  40. add_header Access-Control-Allow-Credentials true;
  41. }
  42. }