求一个 nginx 地址重写规则

2018-07-19 16:07:29 +08:00
 mafeifan

当匹配到地址 http://xxx/sites/app/avatar/0F0993200F910338F0EE638EFDFA1779 要求请求 http://xxx/sites/app/index.php?m=user&c=index&a=avatar&user_id=0F0993200F910338F0EE638EFDFA1779

下面的写法好像不行

	location / {
	   rewrite ^sites/app/avatar/(.*)$  /sites/app/index.php?m=user&c=index&a=avatar&user_id=$1 last;
       try_files $uri $uri/ =404;
	}
883 次点击
所在节点    问与答
5 条回复
yangg
2018-07-19 16:16:05 +08:00
rewrite ^/sites....$

少了个 /
mafeifan
2018-07-19 16:27:47 +08:00
location / {
rewrite ^sites/app/avatar/(.*)$ /sites/app/index.php?m=user&c=index&a=avatar&user_id=$1 last;
try_files $uri $uri/ =404;
}

# pass PHP scripts to FastCGI server
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}

还是报 404,求助啊
mafeifan
2018-07-19 16:40:02 +08:00
rewrite ^/sites/app/avatar/(.*)$ /sites/app/index.php?m=user&c=index&a=avatar&user_id=$1 last;
wu67
2018-07-19 16:40:47 +08:00
\/sites\/app\/avatar\/(.*)$

这样?
imdong
2018-07-19 16:48:54 +08:00
不需要 location 字段也可以噻

server {
listen 80;
root "/web";

# 重写规则
rewrite ^/sites/app/avatar/(.*)$ /sites/app/index.php?m=user&c=index&a=avatar&user_id=$1 last;

location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
...
}
}

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/472391

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX