web-dev-qa-db-ja.com

CodeigniterのNGINXサーバー構成

/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の書き換えを機能させるために必要な構成は何ですか?.

7
Amin

'ci'フォルダーは/var/www/htmlにあるため、現在のドキュメントルート(/var/www/html/ci)を変更したくありませんでした。

代わりに、/etc/nginx/conf.d/default.confに新しいロケーションブロックを作成しました。

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

try_files $uri $uri/ /ci/index.php?/$request_uri;の使用を提案してくれた MertÖksüz に感謝します。

9
Amin

ルートをroot /var/www/html/ciに変更します

Try_filesをtry_files $uri $uri/ /index.php?/$request_uri;に変更します

Fpmパス(unix:/var/run/php-fpm/php-fpm.sock;)が正しいことを確認してください。

5
Mert Öksüz

これは私のために働いた

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

私は同じ問題に直面し、このサイトから少し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コンテナで動作しました。

0