手机端一套代码,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_files $uri $uri/ =404;
fastcgi_connect_timeout 1200s;#原设置为300s
fastcgi_send_timeout 1200s;#原设置为300s
fastcgi_read_timeout 1200s;#原设置为300s
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;
client_max_body_size 10M;
# root /home/lwy/apache-tomcat-8.5.87/webapps/ROOT/WEB-INF/classes/static;
# root /usr/local/apache-tomcat-8.5.87/webapps/ROOT/WEB-INF/classes/static/;
index index.html index.htm;
#rewrite ^/(.*)#(.*)$ /$1 permanent;
#try_files $uri $uri/ /index.html;
#rewrite ^/(.*)#(.*)$ /$1 permanent;
if ( $http_user_agent ~* "mobile|nokia|iphone|ipad|android|samsung|htc|blackberry|MicroMessenger" ){ #// 跳转判断
#rewrite ^/(.*)$ http://43.143.117.226:8099/ redirect; #// redirect表示302跳转(暂时性转移)
#root /home/lwy/apache-tomcat-8.5.87-mob/webapps/ROOT/WEB-INF/classes/static/;
#index index.html index.htm;
set $skip_cache 1;
#rewrite ^/(.*)$ pages/index/index;
proxy_pass http://127.0.0.1:8888;
}
}