Codeigniter的NGINX服务器配置

时间:2017-08-11 11:16:47

标签: php codeigniter nginx centos7

/etc/nginx/conf.d/default.conf

Network

我的codeigniter文件夹是'ci',它位于/ var / www / html / ci中 我需要什么配置来进行网址重写?...

5 个答案:

答案 0 :(得分:4)

将根目录更改为root /var/www/html/ci

将您的try_files更改为try_files $uri $uri/ /index.php?/$request_uri;

确保你的fpm路径(unix:/var/run/php-fpm/php-fpm.sock;)是正确的。

答案 1 :(得分:4)

我不想更改当前文档根目录(/var/www/html) 因为我的'ci'文件夹位于/var/www/html/ci

相反,我在/etc/nginx/conf.d/default.conf中创建了一个新的位置块:

server{
...
    location /ci {
        try_files $uri $uri/ /ci/index.php?/$request_uri;
    }
...
}

感谢Mert Öksüz建议使用try_files $uri $uri/ /ci/index.php?/$request_uri;

答案 2 :(得分:0)

我遇到了同样的问题,并从该站点https://gist.github.com/yidas/30a611449992b0fac173267951e5f17f修改了一些nginx conf

server {

listen 80;

# For https
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server ipv6only=on;
# ssl_certificate /etc/nginx/ssl/default.crt;
# ssl_certificate_key /etc/nginx/ssl/default.key;

server_name sc.hr;
root /var/www/sc/hr/;
index index.php index.html 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 or directory index file exists, else route it to index.php.
        try_files $uri $uri/ /index.php;
}

location ~ \.php$ {
    try_files $uri /index.php =404;
    fastcgi_pass php-upstream;
    fastcgi_index index.php;
    fastcgi_buffers 16 16k;
    fastcgi_buffer_size 32k;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    #fixes timeouts
    fastcgi_read_timeout 600;
    include fastcgi_params;
}

# Deny for accessing .htaccess files for Nginx
location ~ /\.ht {
        deny all;
    }

# Deny for accessing codes
    location ~ ^/(application|system|tests)/ {
        return 403;
    }
}

此配置文件适用于我的laradock nginx容器。

答案 3 :(得分:0)

这对我有用

location ~* \.php$ {
                fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
                include fastcgi.conf;
        }

答案 4 :(得分:0)

如果有人在ubuntu 18.04配置上寻找CI 4 nginx:

root /var/www/ci/public;

location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to displaying a 404.

    # this is not working for the first get argument :
    # try_files $uri $uri/ /index.php?/$request_uri;

    # use this :
    try_files $uri $uri/ /index.php$is_args$args;
}