lnmpa环境,二级域名绑定根目录文件夹,访问进行跳转问题
如标题,我现在有一个子域名站点绑定了根目录的文件夹m,现在访问https://www.x.com/m 没有跳转到https://m.x.com,或者访问https://www.x.com/m/* 这里面所有的文件夹都无法跳转到对应的移动站https://m.x.com/*我在www.x.conf 配置文件server写了这个代码,但无效
location ~* ^/m/
{
rewrite ^/m/(.*)$ https://m.x.com/$1 permanent;
}
不知道什么原因,请教一下各位,谢谢!
server
{
listen 80;
#listen [::]:80;
server_name www.snsnz.com snsnz.com;
index index.html;
return 301 https://www.snsnz.com$request_uri;
if ($host != 'www.snsnz.com' )
{
rewrite ^/(.*)$ https://www.snsnz.com/$1 permanent;
}
if( $http_user_agent ~* "(iPhone|iPad|iPod|iOS|Android|Mobile|nokia|samsung|htc|blackberry)")
{
rewrite ^/tag/(.*)$ https://m.snsnz.com/tag/$1 permanent;
}
root/home/wwwroot/www.snsnz.com;
#error_page 404 /404.html;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
location ~* ^/m/
{
rewrite ^/m/(.*)$ https://m.snsnz.com/$1 permanent;
}
include proxy-pass-php.conf;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
access_log/home/wwwlogs/www.snsnz.com.log;
} caiheqing 发表于 2023-7-4 17:47
前面都 return 301 了后面肯定就都不执行了 本帖最后由 caiheqing 于 2023-7-5 09:17 编辑
licess 发表于 2023-7-5 08:11
前面都 return 301 了后面肯定就都不执行了
谢谢军哥的回复,那我把return 301 放在所有的if后面,好像也不行,代码
server
{
listen 80;
#listen [::]:80;
server_name www.snsnz.com snsnz.com;
index index.html;
if ($host != 'www.snsnz.com' )
{
rewrite ^/(.*)$ https://www.snsnz.com/$1 permanent;
}
if( $http_user_agent ~* "(iPhone|iPad|iPod|iOS|Android|Mobile|nokia|samsung|htc|blackberry)")
{
rewrite ^/tag/(.*)$ https://m.snsnz.com/tag/$1 permanent;
}
root/home/wwwroot/www.snsnz.com;
#error_page 404 /404.html;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
location ~* ^/m/
{
rewrite ^/m/(.*)$ https://m.snsnz.com/$1 permanent;
}
return 301 https://www.snsnz.com$request_uri;
include proxy-pass-php.conf;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
access_log/home/wwwlogs/www.snsnz.com.log;
} caiheqing 发表于 2023-7-5 09:15
谢谢军哥的回复,那我把return 301 放在所有的if后面,好像也不行,代码
只要单独使用了 return 301 就不会再进行匹配了,除非使用了 location 才会有先后顺序
把 return 301 加到一个 location / { } 里面
如
location / {
return xxxx;
} licess 发表于 2023-7-6 09:19
只要单独使用了 return 301 就不会再进行匹配了,除非使用了 location 才会有先后顺序
把 return 301 加 ...
谢谢军哥回复,我加了一行代码
location / {
return 301 https://www.snsnz.com$request_uri;
}
报错:nginx:duplicate location "/" in /uer/local/nginx/conf/proxy-pass-php.conf:2
根据提示是有重复使用项。我在其他location下面加了return 301 ,但还是无法跳转,如访问https://www.snsnz.com/m, 没跳转到https://m.snsnz.com ,访问https://www.snsnz.com/m/jianfei/jianfeishipu/ 没有跳转到https://m.snsnz.com/jianfei/jianfeishipu/类似栏目跳转。 caiheqing 发表于 2023-7-6 10:20
谢谢军哥回复,我加了一行代码
报错:nginx:duplicate location "/" in /uer/local/nginx/conf/p ...
include proxy-pass-php.conf;
删掉就行了 licess 发表于 2023-7-7 08:18
include proxy-pass-php.conf;
删掉就行了
谢谢军哥的回复!现在http都可以跳转了,但https就不行,如
打开https://www.snsnz.com/m/shehua/shechipinpai/ 没有跳转到https://m.snsnz.com//shehua/shechipinpai/
打开http://snsnz.com/m/shehua/shechipinpai/ 直接跳转到https://www.snsnz.com/m/shehua/shechipinpai/这里应该跳转到https://m.snsnz.com/shehua/shechipinpai/
是不是这行代码还需要优化?
location ~* ^/m/
{
rewrite ^/m/(.*)$ https://m.snsnz.com/$1 permanent;
}
补充内容 (2023-7-7 23:12):
解决了,谢谢军哥这几天赐教 caiheqing 发表于 2023-7-7 14:15
谢谢军哥的回复!现在http都可以跳转了,但https就不行,如
打开https://www.snsnz.com/m/shehua/shechip ...
那就是没有匹配上,可能配置上你哪里可能还有问题
页:
[1]