如何在NGINX服务器中配置Codeigniter? .htaccess无法正常工作

时间:2018-07-09 02:27:36

标签: .htaccess codeigniter nginx

如何在NGINX服务器中配置Codeigniter? .htaccess在这里不起作用,我没有没有root权限。只有我可以使用FTP上传文件并可以访问数据库。

在哪里可以使用此配置...?

    server {
        server_name domain.tld;

        root /var/www/codeignitor;
        index index.html index.php;

        # 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$ {
                fastcgi_pass 127.0.0.1:9000;
                include fastcgi.conf;
        }
}

参考:https://www.nginx.com/resources/wiki/start/topics/recipes/codeigniter/

1 个答案:

答案 0 :(得分:0)

您应该与网络管理员联系,以访问配置文件/etc/nginx/conf.d/default.conf。需要正确配置才能使路由工作。您可以像以下代码一样配置nginx服务器文件,以使路由工作。

server{ listen 80; listen [::]:80; server_name 192.168.56.101 192.168.101.100 localhost; root /var/www/html; index index.php index.html index.htm; location / { try_files $uri $uri/ =404; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /var/www/html; } location /ci { try_files $uri $uri/ /ci/index.php?/$request_uri; }location ~ \.php$ { try_files $uri $uri/ /ci/index.php?/$request_uri; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~ /\.ht { deny all; } }