关于nginx 404错误的Django和wordpress

时间:2016-10-01 04:49:51

标签: django wordpress nginx

我在example.com上运行了django,我需要在我的服务器上添加一个Wordpress,将是example.com/blog,也许不起作用(404错误):

listen      80;
server_name www.example.com;    

location ^~ /blog/ {
        root    /www/blog;
        index   index.html index.htm index.php;
        try_files  $uri =404;

        location ~ \.php {
                root /www/blog;
                fastcgi_split_path_info ^(.*\.php)(.*)$;
                include fastcgi_params;

                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_param PATH_INFO $fastcgi_path_info;
                fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
                fastcgi_pass 127.0.0.1:9000;
        }

}

location / {
    uwsgi_pass  unix:/tmp/myapp.sock;
    include     /www/webapp/system/uwsgi_params; # the uwsgi_params file you installed
    uwsgi_read_timeout 300;
}

2 个答案:

答案 0 :(得分:1)

我也遇到了这个问题。在这里,您可以查看我的位置配置。

location /blog {
    root /var/www/html; 

    try_files $uri $uri/ /blog/index.php?$args;
    index index.php; 

    location ~ [^/]\.php(/|$) { 
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;

        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO       $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;

        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php; 
    } 

}

适合您的配置:

location /blog {
     root    /www/blog; 

    try_files $uri $uri/ index.php?$args;
    index index.php; 

    location ~ [^/]\.php(/|$) { 
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;

        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO       $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;

        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php; 
    } 

}

答案 1 :(得分:0)

@Levi配置给我一些启示,我需要修改,因为我收到404错误或没有指定输入文件。

    location /blog {
         alias    /www/blog;

        try_files $uri $uri/ index.php?$args;
        index index.php;

        location ~ [^/]\.php(/|$) {
            fastcgi_split_path_info ^(.+?\.php)(/.*)$;

            include fastcgi_params;
            fastcgi_param  SCRIPT_FILENAME  /www/blog$fastcgi_script_name;
            fastcgi_param SCRIPT_FILENAME $request_filename;

            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
        }

    }