![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/e7cc37730cb91a4150fd92c7754a4cd4.png#pic_center)
nodejs解决跨域
1.下载nginx
nginx下载地址
2.找到安装地址下的/conf/nginx.conf文件
#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 8888; #本机端口号
server_name localhost; #本机域名
# location / {
# root /reportForm;
# index index.html index.htm;
# }
location /epa/ { #后台项目名
# 前台请求举例:$.ajax({
# url: 'http://192.168.3.149:8080/epa/getData'
#})
proxy_pass http://192.168.3.149:8080; #后台项目运行地址
proxy_cookie_domain 192.168.3.149 localhost; #修改cookie里域名
}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
3.返回上级目录,运行nginx.exe
4.最后,如果登录验证过不去的话,看看cookie里存的数据,实在不行就让后台懒蛋把登录验证取消了,不解决跨域,还不注释登录验证,就拿刀砍死他,大砍刀,一块钱四个,嘿嘿。