自己写了一个网站,绑定域名
xxx.com ,希望通过
xxx.com/en/也可以访问.
例如
xxx.com/product/detail.html 这个页面,用
xxx.com/en/product/detail.html 也能够访问,希望能够做到这样的效果.
因为是用 Django 写的,应该也是可以用路由配置来达到这个效果,不过觉得丢给 NGINX 去做可能更清晰一点.
环境是 Python+Django+uWSGI+NGINX. 下面是我 NGINX 的配置,请帮我看一下吧.
```nginx
# the upstream component nginx needs to connect to
upstream XXX_EN {
server unix:///home/wwwroot/PY_XXX_EN/web.sock; # for a file socket
}
# configuration of the server
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
server_name
en.XXX.com;
# max upload size
client_max_body_size 75M; # adjust to taste
location /cn {
rewrite ^/
http://www.XXX.com/; }
location /static {
alias /home/wwwroot/STATIC_XXX_EN/static;
expires 12h;
}
location /en {
uwsgi_pass XXX_EN;
include /usr/local/nginx/conf/uwsgi_params;
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass XXX_EN;
include /usr/local/nginx/conf/uwsgi_params; # the uwsgi_params file you installed
}
}
```
我用下面的配置来实现我说的效果,但是无效.
```nginx
location /en {
uwsgi_pass XXX_EN;
include /usr/local/nginx/conf/uwsgi_params;
}
```
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
https://www.v2ex.com/t/239865
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.