![](/img/trans.png)
[英]How to run django and wordpress on NGINX server using same domain?
[英]How to run Django and Wordpress using Nginx and Gunicorn at the same domain?
我有一个在域(例如www.example.com)上运行的Django应用
我想创建一个Wordpress登陆页面,并将该登陆页面指向主页URL www.example.com,并将wordpress管理站点指向www.example.com/admin或www.example.com/wp-admin。 所有其他URL应由Django提供。
所以,我想要:
到目前为止,这是我使用Django的Nginx配置:
upstream django_server {
server unix:/path/to/gunicorn.sock fail_timeout=0;
}
server {
listen 80;
server_name www.example.com example.com
client_max_body_size 4G;
access_log /path/to/nginx-access.log;
error_log /path/to/nginx-error.log;
location /static/ {
alias /path/to/static/;
}
location /media/ {
alias /path/to/media/;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://django_server;
break;
}
}
error_page 500 502 503 504 /500.html;
location = /500.html {
root /path/to/static/;
}
}
任何帮助将不胜感激。
WordPress使用不确定的URL集,因此在该URL与Django可用的URL集之间有一个清晰的分区非常重要。 最好的解决方案是将WordPress放在一个子目录中(这很简单)。
例如:
server {
...
# existing Django configuration
...
location = / {
return $scheme://$host/blog/;
}
location ^~ /blog {
alias /path/to/wordpress;
index index.php;
if (!-e $request_filename) { rewrite ^ /blog/index.php last; }
location ~ /wp-content/uploads/ { expires 30d; }
location ~ \.php$ {
if (!-f $request_filename) { rewrite ^ /blog/index.php last; }
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
...
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
if (!-f $request_filename) { rewrite ^ /blog/index.php last; }
expires 30d;
}
}
}
您将需要设置站点和家庭URL。 有关详细信息,请参见此文档 。
有关更多信息,请参见此文档 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.