【问题标题】:NGINX server configuration for CodeigniterCodeigniter 的 NGINX 服务器配置
【发布时间】:2021-09-01 14:24:54
【问题描述】:

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

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 ~ \.php$ {
    try_files $uri =404;
    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;
}
}

我的 codeigniter 文件夹是“ci”,它位于 /var/www/html/ci url重写需要什么配置?...

【问题讨论】:

  • Doc: Nginx for Codeigniter 你之前检查过吗?
  • 是的,我做到了,但没用...
  • 更改根root /var/www/html/ci
  • 你能改变那部分吗try_files $uri $uri/ /index.php?/$request_uri;

标签: php codeigniter nginx centos7


【解决方案1】:

我不想更改当前文档根目录 (/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;

这个也可以:

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

【讨论】:

  • vestacp with nginx & php-fpm 合作,谢谢
【解决方案2】:

将您的根更改为root /var/www/html/ci

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

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

【讨论】:

    【解决方案3】:

    我遇到了同样的问题并从这个站点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;
        }
    }
    

    这个 conf 在我的 laradock nginx 容器上运行。

    【讨论】:

      【解决方案4】:

      这对我有用

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

      【讨论】:

        【解决方案5】:

        如果有人在 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;
        }
        

        【讨论】:

          猜你喜欢
          • 2017-05-12
          • 2018-05-02
          • 1970-01-01
          • 2013-10-05
          • 1970-01-01
          • 2014-08-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多