簡體   English   中英

Codeigniter 的 NGINX 服務器配置

[英]NGINX server configuration for Codeigniter

/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 文件夾是位於 /var/www/html/ci 中的“ci”文件夾,我需要什么配置才能進行 url 重寫?...

我不想更改當前文檔根目錄 ( /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; .

將您的根更改為root /var/www/html/ci

將您的 try_files 更改為try_files $uri $uri/ /index.php?/$request_uri;

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

我遇到了同樣的問題並從這個站點修改了一點 nginx conf https://gist.github.com/yidas/30a611449992b0fac173267951e5f17f

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 容器上工作。

這對我有用

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM