简体   繁体   中英

nginx - codeigniter 404 error for all urls

I have uploaded my files(Codeigniter Framework) in abcd directory ( url : example.com/abcd ) . All the links inside give 404 error . For removing index.php, I have placed this nginx.conf file in my root directory ( on server : /.../abcd/) Here is the code for the nginx.conf file :

server {  
    server_name example.com/abcd;
    root /..../abcd;

    index index.html index.php index.htm;

    # set expiration of assets to MAX for caching
    location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
        expires max;
        log_not_found off;
    }

    location / {
        # Check if a file exists, or route it to index.php.
        try_files $uri $uri/ /index.php;
    }

    location ~* \.php$ {
        fastcgi_pass example.com/abcd;
        fastcgi_index index.php;
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

}

In apache, it was easy using rewrite, i am now stuck with nginx. Please help, I am using nginx for the first time

Try below code.. taken from https://serverfault.com/questions/695521/codeigniter-in-subdirectory-on-nginx-404

 location /abcde/ {
        alias  /var/www/abcde/;
        try_files $uri $uri/ /abcde/index.php;

        location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_index   index.php;
            fastcgi_pass    backend;
            include /etc/nginx/fastcgi_params;
            fastcgi_param   SCRIPT_FILENAME $request_filename;
        }
    }

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