nginx放置了手机端与电脑端的两个项目,电脑端做了判断,手机访问电脑端网站时会直接重定向到6060端口这个网站。但是为什么6060端口手机端网站PC访问却无法重定向到shinel.top这个网站呢,
nginx配置文件
重定向代码
# 判断手机登录,重定向指定页面
if ($http_user_agent ~* (mobile|nokia|iphone|ipad|android|samsung|htc|blackberry)) {
rewrite ^(.*) http://shinel.top:6060 redirect;
}
#判断是否是pc端,是pc端重定向指定域名
if ($http_user_agent !~* "(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iem obile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox
|netfront|operam(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vo dafone|wap|windows ce|xda|xiino") {
rewrite ^/(.*) https://shinel.top redirect;
}
nginx配置文件
worker_processes auto;
worker_rlimit_nofile 51200;
events
{
worker_connections 51200;
multi_accept on;
}
http {
include mime.types;
#include luawaf.conf;
include proxy.conf;
default_type application/octet-stream;
# 下5行为不缓存配置
expires -1;
if_modified_since off;
add_header Last-Modified "";
add_header Cache-Control no-cache;
etag off;
server_names_hash_bucket_size 512;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 50m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
limit_conn_zone $binary_remote_addr zone=perip:10m;
limit_conn_zone $server_name zone=perserver:10m;
server_tokens off;
access_log off;
# 电脑端
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root c:/wwwroot/127.0.0.1;
# 判断手机登录,重定向指定页面
if ($http_user_agent ~* (mobile|nokia|iphone|ipad|android|samsung|htc|blackberry)) {
rewrite ^(.*) http://shinel.top:6060 redirect;
}
index index.html index.htm;
}
location /nginx_status {
allow 127.0.0.1;
deny all;
stub_status on;
access_log off;
}
}
include vhost/*.conf;
#加载vhost目录下的虚拟主机配置文件
# 手机端
server {
listen 6060;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root c:/wwwroot/qiulingstudio-mobile;
#判断是否是pc端,是pc端重定向指定域名
if ($http_user_agent !~* "(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iem obile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox
|netfront|operam(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vo dafone|wap|windows ce|xda|xiino") {
rewrite ^/(.*) http://shinel.top redirect;
}
index index.html index.htm;
}
location /nginx_status {
allow 127.0.0.1;
deny all;
stub_status on;
access_log off;
}
}
}
原谅我没看懂你的访问说明😂
能否用ABC这样来表达一下你的机器访问拓扑呢。。。
例如,nginx部署在B,A为PC,C为手机,,现在A访问 B的6060端口,会重定向到shinel.top这个网站;而C访问 B的6060端口没重定向到shinel.top这个网站;
这样描述,就很清晰了且知道情况😂现在看你题目,原来我真未搞清你的访问情况。。。而且nginx还部署了手机项目和电脑项目。。。然后分了电脑访问和手机访问??之后测试的情况,就没看明文字说明了🤣