nginx配置,解决前端跨域调用问题


#user nobody;
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 {
worker_connections 1024;
}


http {
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 8080; #端口号
server_name localhost; #监听服务名称

location / {
root D:/yayingH5/yayingH5/unpackage/dist/build/h5; #前端页面地址
index index.html index.htm;
}

location /wx/ {
# ilead back-end address
proxy_pass http://172.16.205.99:8080/wx/; #跨域调用路径
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

}

}

原文地址:https://www.cnblogs.com/ZenoLiang/p/15787903.html