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; } } }