简体   繁体   中英

Codeigniter in Wordpress how to config Nginx

Search for a long time did not find the answer, thank you here first

Here is my directory: Wordpress in /var/projects/root Codeigniter in /var/projects/root/codeigniter/

Here is my nginx server config:

listen 80;
server_name nginx.local.com;
root /var/projects/root;
error_log  /var/projects/log/error.log warn;
access_log  /var/projects/log/access.log main;

if ($host != 'nginx.local.com'){
   rewrite ^/(.*) http://nginx.local.com/$1 permanent;
}

location / {
    index index.php index.html index.html;
}

rewrite ^.*/files/(.*)$ /wp-includes/ms-files.php?file=$1 last;
if (!-e $request_filename) {
    rewrite ^.+?(/wp-.*) $1 last;
    rewrite ^.+?(/.*\.php)$ $1 last;
    rewrite ^ /index.php last;
}

location ~ \.php$ {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

location ~ /codeigniter/ {
    if (!-e $request_filename)
    {
        rewrite ^/(.*)$ /index.php/$1 last;
        break;
    }
}

location /codeigniter {
    try_files $uri $uri/ /codeigniter/index.php?$query_string;
}

I have tried many methods, the Codeigniter has become the original code, now only http://nginx.local.com/codeigniter and http://nginx.local.com/codeigniter/index.php can access (is welcome page)

The following pages is 404 Not Found http://nginx.local.com/index.php/codeigniter/welcome/index http://nginx.local.com/codeigniter/welcome/index http://nginx.local.com/index.php/codeigniter/welcome/test

I tried out the solution.

server {
    listen 80;
    server_name nginx.local.com;
    root /var/projects/root;
    error_log  /var/projects/log/error.log warn;
    access_log  /var/projects/log/access.log main;

    if ($host != 'nginx.local.com'){
       rewrite ^/(.*) http://nginx.local.com/$1 permanent;
    }

    location / {
        index index.php index.html index.html;
        if (!-e $request_filename) {
            rewrite ^.+?(/wp-.*) $1 last;
            rewrite ^.+?(/.*\.php)$ $1 last;
            rewrite ^ /index.php last;
        }
        rewrite ^.*/files/(.*)$ /wp-includes/ms-files.php?file=$1 last;
    }

    #Here is codeignter path
    location ~ /codeignter {
        try_files $uri $uri/ /index.php?$query_string;
        location ~ \.php($|/) {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  evindex.php;
            fastcgi_split_path_info ^(.+\.php)(.*)$;
            fastcgi_param   PATH_INFO $fastcgi_path_info;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }

    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM