自己写了一个网站,绑定域名 xxx.com ,希望通过 xxx.com/en/也可以访问.
例如 xxx.com/product/detail.html 这个页面,用 xxx.com/en/product/detail.html 也能够访问,希望能够做到这样的效果.
因为是用 Django 写的,应该也是可以用路由配置来达到这个效果,不过觉得丢给 NGINX 去做可能更清晰一点.
环境是 Python+Django+uWSGI+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
}
}
我用下面的配置来实现我说的效果,但是无效.
location /en {
uwsgi_pass XXX_EN;
include /usr/local/nginx/conf/uwsgi_params;
}
1
eternityz 2015-11-29 21:10:57 +08:00
```
rewrite ^/en/(.*) /$1; ``` |
2
binnchx 2015-11-29 21:26:15 +08:00
location {
rewrite ^/en/(.*) /$1; } |
3
binnchx 2015-11-29 21:26:31 +08:00
location {
rewrite ^/en/(.*) /$1 break; } |
4
JJaicmkmy 2015-11-30 08:16:46 +08:00 via iPad
如果网站的内容很少变动的话,我认为最简单的方法是把网站在./en/也放一份。
|
5
zhangv 2015-11-30 09:46:17 +08:00
查一下 nginx 的 rewrite
|