简体   繁体   中英

CodeIgniter 3, Nginx rewrite how to?

I installed CodeIgniter 3 after a long time on PHP-fpm and nginx (Ubuntu). Previously I had always used CodeIgniter on Windows and configuring it on Windows and Apache it was a piece of cake. Now I wanna install it on nginx, because I wanna use nginx-push-stream-module, which isn't possible from apache.

Now when I'm configuring it, its not working.

If I type localhost/myexample.com or localhost/myexample.com/index.php it works ( myexample.com is the name of that directory)

but when I try to access

localhost/myexample.com/welcome

or

localhost/myexample.com/welcome/index

or

localhost/myexample.com/index.php/welcome

or

localhost/myexample.com/index.php/welcome/index

it doesn't work in any of the 4 cases (with or without index.php)

My root directory is /var/www/html/myexample.com

I tried all of the rewrite settings available online (including the following settings) from different blog posts etc (as I'm not used to nginx myself)

server {
    server_name myexample.com;
    root /var/www/html/myexample.com/;
    index index.php index.html index.htm;
    location / {
        try_files $uri $uri/ /index.php;
    }

    location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
        expires           15d;
    }

    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www/html/myexample.com/index.php;
        fastcgi_param  REQUEST_URI      $request_uri;
        fastcgi_param  QUERY_STRING     $query_string;
        fastcgi_param  REQUEST_METHOD   $request_method;
        fastcgi_param  CONTENT_TYPE     $content_type;
        fastcgi_param  CONTENT_LENGTH   $content_length;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
     }
}

Edit: I also tried the method mentioned at Nginx's official website, but that's also not working.

You should modify your /etc/hosts and add this line:

127.0.0.1 myexample.com

And after that use myexample.com or myexample.com/welcome to access your CodeIgniter site

First - confirm what the server name is going to be. Set that in the your hosts file, then confirm the web root.

So in /etc/hosts add

127.0.0.1 myexample.com

Then your index.php file should be in

/var/www/html/myexample.com/

You should get CI up and working on the url

http://myexample.com

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