nginx.confg
# For more information on configuration, see:# * Official English Documentation: http://nginx.org/en/docs/# * Official Russian Documentation: http://nginx.org/ru/docs/user nginx;worker_processes auto;error_log /var/log/nginx/error.log;pid /run/nginx.pid;# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.include /usr/share/nginx/modules/*.conf;events { worker_connections 1024;}http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; include /etc/nginx/conf.d/*.conf}
confg.d文件夹下example.conf
server { listen 80; server_name labour.bringbuys.com; access_log labour.access.log; gzip on; // 开启gzip压缩优化,前端vue-cli用webpack配置build时,开启productionGzip为true。 gzip_min_length 1k; gzip_buffers 4 8k; gzip_http_version 1.1; gzip_types text/plain application/javascript application/x-javascript text/javascript text/xml text/css; location /d/resource { alias /data/download/files; autoindex off; autoindex_exact_size off; } location / { proxy_connect_timeout 300s; proxy_send_timeout 300s; proxy_read_timeout 300s; add_header Cache-Control 'no-cache,max-age=0'; root /data/src/labour-system/dist; try_files $uri $uri/ /index.html last; index index.html index.html; gzip_static on; } location /api/ { proxy_connect_timeout 300s; proxy_send_timeout 300s; proxy_read_timeout 300s; proxy_http_version 1.1; proxy_pass http://api.labour.bringbuys.com/; proxy_set_header Host "api.labour.bringbuys.com"; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 100m; access_log on; #支持跨域访问的问题 add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Headers X-Requested-With; add_header Access-Control-Allow-Methods GET,POST,OPTIONS; add_header Access-Control-Allow-Credentials true; }}