Problem using CODEIGNITER on Nginx server

Asked

Viewed 897 times

1

My site was hosted at UOLHOST and worked perfectly with the following . htaccess

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt)

RewriteRule ^(.*)$ index.php?r=$1 [L,QSA]

I’m migrating to an EC2 on Amazon and will use Nginx as a web server in conjunction with PHP-FPM.

Who made the site said that his administration used CODEIGNITER.

I have changed config.php settings within /application/config and only the website works, your administration, does not.

I tried that:

    server {
    listen 80;
    root /usr/share/nginx/html/meudominio.com.br;
    index index.php;
    server_name meudominio.com.br www.meudominio.com.br;
    access_log /var/log/nginx/meudominio.com.br.access;
    error_log /var/log/nginx/meudominio.com.br.error error;
    location / {
    try_files $uri /index.php?r=$uri&$args;
    }

    location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    }
    location /controle {
    }
    location ~ /\.ht {
    deny all;
    }
    }

The folder "CONTROL" is where the administration of the website.

Alternatively, I created another block and a sub-domain pointing to the control folder. As below:

    server {
    listen 80;
    root /usr/share/nginx/html/meudominio.com.br/controle;
    index index.php;
    server_name adm.meudominio.com.br;
    access_log /var/log/nginx/meudominio.com.br.access;
    error_log /var/log/nginx/meudominio.com.br.error error;
    location / {
    try_files $uri /index.php?r=$uri&$args;
    }

    location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    }
    }

By accessing the website administration at the Adm.meudominio.com.br I can log in and view all the administrative items of the website.

However, when I upload images to the server, their path is modified, according to the root I set for the sub-domain.

/usr/share/Nginx/html/meudominio.com.br/control

When in fact I need the images to be sent based on root "/usr/share/Nginx/html/meudominio.com.br"

What’s going on?

2 answers

1

I was able to solve the problem by including the following lines

location /controle {
    try_files $uri $uri/ /controle/index.php?$args;
}

just above:

location ~ \.php$ {

With this, the system using CODEIGNITER behaved in APACHE using the informed . hataccess at the beginning of the publication.

-2

Just add inside the Nginx.conf

server{

Location / { #try_files $Uri $Uri/ =404; try_files $Uri $Uri/ /index.php? $args; } }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.