user nginx; worker_processes auto; error_log /var/log/nginx/error.log notice; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; server_tokens off; 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; client_max_body_size 100M; client_body_buffer_size 100M; fastcgi_buffer_size 128k; fastcgi_buffers 8 128k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; #gzip on; server { listen 80; server_name localhost; charset utf-8; location / { # 网站根目录,此处使用容器内的路径 root /usr/local/www/dist; # 默认首页 index index.html; # 尝试从磁盘找到请求的文件,如果不存在则跳转到 index.html try_files $uri $uri/ /index.html; } location /APP { # 网站根目录,此处使用容器内的路径 alias /usr/local/www/APP; # 尝试从磁盘找到请求的文件,如果不存在则跳转到 index.html #index cqjj.apk; # try_files $uri $uri/ /index.html; } location /bigScrap { # 网站根目录,此处使用容器内的路径 alias /usr/local/www/bigScrap; # 默认首页 index index01.html; # 尝试从磁盘找到请求的文件,如果不存在则跳转到 index.html try_files $uri $uri/ /bigScrap/index01.html; } location /dev-api/ { #rewrite ^.+api/?(.*)$ /$1 break; #这样写有问题,在网上看有人这样写,发现有问题 rewrite ^/dev-api/(.*)$ /$1 break; #必须的写这个,使用nginx的rewrite对uri进行重写 下面这行也要改为api proxy_pass http://192.168.1.2:28080/; #跨域转发路由地址 proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /screen/ { #rewrite ^.+api/?(.*)$ /$1 break; #这样写有问题,在网上看有人这样写,发现有问题 rewrite ^/screen/(.*)$ /$1 break; #必须的写这个,使用nginx的rewrite对uri进行重写 下面这行也要改为api proxy_pass http://192.168.1.2:28080/; #跨域转发路由地址 proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } }