技术解析
自己写了一个网站,绑定域名 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
}
}