vue+nginx时nginx配置:以下标红,主要配置
# worker_processes 值越大,可以支持的并发处理量也越多 # 工作进程:数目。根据硬件调整,通常等于CPU数量或者2倍于CPU worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; # events 块涉及的指令主要影响 Nginx 服务器与用户的网络连接 # 表示每个 work process 支持的最大连接数为 1024 events { worker_connections 1024; } http { # http全局块 # http全局块配置的指令包括文件引入、MIME-TYPE 定义、日志自定义、连接超时时间、单链接请求数上限等 include mime.types; default_type application/octet-stream; #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 logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 5004; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root C:/project/jenkins/www; index report.html; autoindex on; add_header Cache-Control no-store; autoindex_exact_size off; autoindex_localtime on; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } # 自动化平台 server { listen 5005; server_name localhost; location / { root C:/project/nginx-1.16.0/html/dist; index index.html index.htm; try_files $uri $uri/ /index.html; # vue页面刷新重定向,否则页面刷新404 } # 配置跨域代理 location /api { rewrite ^/api/(.*)$ /$1 break; proxy_pass http://localhost:8088; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_read_timeout 300; proxy_send_timeout 300; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }