手机端一套代码,pc端一套代码,同域名访问怎么办?
nginx来助你
我们进入nginx配置文件 监听 / 当不是手机端的时候转发到3000 是手机转发到8888端口
然后将两个项目启动在响应的端口上就行
location / {
# as directory, then fall back to displaying a 404.
#rewrite ^(.*)$ /index.html last;
proxy_pass http://localhost:3000;
proxy_http_version 1.0;
# 设置允许 CORS
#add_header 'Access-Control-Allow-Origin' '*';
#add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
#add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
#add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Fonwarded-For $proxy_add_x_forwarded_for;
#try