0
當前有uWSGI調解nginx和Django之間的請求和響應。有兩個站點A和B:Nginx爲特定路徑與另一個域服務Django(uWSGI套接字)
- A)alpha.com
- B)www.beta.com
現在我想通過指向nginx的從路徑alpha.com/awards
服務站點B B的uWSGI插座爲/home/web/beta/uwsgi/site.sock
,使得可以從www.beta.com/one
和alpha.com/awards/one
兩者訪問頁面P1,或者可以從www.beta.com/two
和alpha.com/awards/two
兩者訪問P2。
網址是在django中定義的,而不是nginx中的靜態資源。
我該怎麼做?
的配置文件:
# /etc/nginx/sites-available/alpha
server {
listen 80;
listen 443 ssl spdy;
server_name www.alpha.com;
# Set certificate files.
ssl_certificate /etc/nginx/cert/alpha.cert;
ssl_certificate_key /etc/nginx/cert/alpha.key;
return 301 $scheme://alpha.com$request_uri;
}
server {
listen 443 ssl spdy;
server_name alpha.com;
# Set certificate files.
ssl_certificate /etc/nginx/cert/alpha.cert;
ssl_certificate_key /etc/nginx/cert/alpha.key;
# Rewrite all news articles to HTTP, because comments don't work in HTTPS.
#rewrite "^/(news/\d+/\d+/\d+/.*)$" http://$http_host/$1 redirect;
include sites-available/alpha.shared;
}
# /etc/nginx/sites-available/alpha.shared
root /usr/share/nginx/www;
index index.html index.htm;
# Use the custom error page.
error_page 500 /error/500.html;
error_page 502 /error/502.html;
# Serve custom error pages from the Django templates directory.
location ^~ /error/ {
internal;
alias /home/web/alpha/templates/;
}
location/{
include uwsgi_params;
uwsgi_pass unix:/home/web/alpha/uwsgi/site.sock;
}
# Set up all static files.
location /robots.txt {
alias /home/web/alpha/static/robots.txt;
}
location /static/css/ {
include expires_headers;
alias /home/web/alpha/static/css/;
}
# /etc/nginx/sites-available/beta
server {
listen 80;
listen 443 ssl spdy;
server_name beta.co.uk;
# Set certificate files.
ssl_certificate /etc/nginx/cert/2015-beta.cert;
ssl_certificate_key /etc/nginx/cert/2015-beta.key;
return 301 $scheme://www.beta.co.uk$request_uri;
}
server {
listen 443 ssl spdy;
# Serve from www.
server_name www.beta.co.uk;
# Set certificate files.
ssl_certificate /etc/nginx/cert/2016-beta.crt;
ssl_certificate_key /etc/nginx/cert/2016-beta.key;
include sites-available/beta.shared;
}
server {
listen 80;
# Serve from www.
server_name www.beta.co.uk;
# Redirect all HTTP traffic to HTTPS
return 302 https://www.beta.co.uk$request_uri;
}
# /etc/nginx/sites-available/beta.shared
root /usr/share/nginx/www;
index index.html index.htm;
error_page 500 /error/500.html;
error_page 502 /error/502.html;
# Serve custom error pages from the Django templates directory.
location ^~ /error/ {
internal;
alias /home/web/beta/templates/;
}
location/{
include uwsgi_params;
uwsgi_pass unix:/home/web/beta/uwsgi/site.sock;
}
# Set up all static files.
location /static/css/ {
include expires_headers;
alias /home/web/beta/static/css/;
}