如何使用相同的域在NGINX服务器上运行django和wordpress?

Muk*_*esh 4 php python django wordpress nginx

我尝试了很多方法但不知道如何在example.com 运行Django在example.com/blog 运行wordpress

以下是Django和Wordpress的运行项目目录结构.

Django app dir - /home/ubuntu/django

Django app成功运行 - example.com:8000

Wordpress目录 - /var/www/html/blog

Wordpress成功运行 - example.com

Nginx配置

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /var/www/html/blog;
    index index.php index.html index.htm;

    server_name example.com;

    location / {
            # try_files $uri $uri/ =404;
            try_files $uri $uri/ /index.php?q=$uri&$args;
    }

    error_page 404 /404.html;

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
            root /usr/share/nginx/html;
    }

    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
    }
}
Run Code Online (Sandbox Code Playgroud)

注意 -由gunicorn运行的Django应用程序,我知道子域可能是解决方案,但我不希望这样.

如何为Wordpress和Django编写nginx配置,以在example.com和examplepress.com/blog上运行Django应用程序

Muk*_*esh 5

谢谢 亚历克斯帮助我解决这个问题.

这是解决方案

Django app dir - /home/ubuntu/django

Wordpress目录 - /var/www/html/blog

NGINX Conf文件

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;
    server_name example.com;

    location / {
            proxy_pass http://127.0.0.1:8000;
            proxy_redirect off;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For          

            $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
    }

    location ~ /blog/.*\.php$ {
            root /var/www/html;
            index index.php index.html index.htm;
            set $php_root /var/www/html/blog;

            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
    }

    location /blog {
            root /var/www/html;
            index index.php index.html index.htm;
            set $php_root /var/www/html/blog;

            try_files $uri $uri/ /blog/index.php;
    }

location /static/ {
            alias /home/ubuntu/django/your_app_name/static/static_root/;
    }

    location /media/ {
        alias /home/ubuntu/django/your_app_name/media/ ;
    }

}
Run Code Online (Sandbox Code Playgroud)

注意 -请使用wordpress的wp-location表中的http://example.com/blog替换您的家庭和siteurl

现在您在example.com上运行Django应用程序

现在您的博客在example.com/blog上运行