私は nginx の初心者で、StackOverflow で問題を見つけようとしましたが、フォーラムで正確な問題は見つかりませんでした。nginx、MySQL、php-fpm のインストールに成功した後、正常に動作していた php.info をテストしました。
CodeIgniterプロジェクトをApacheサーバーからnginxに移行しています。nginx.conf
コードのあるファイルを編集します
server {
listen 80;
server_name 173.249.40.xxx;
# note that these lines are originally from the "location /" block
root /usr/share/nginx/html/ci;
index index.html index.htm index.php;
location /ci {
try_files $uri $uri/ /index.php;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/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;
}
}
php.info
私のパスでは正常に動作していましたが、呼び出されたときのようにhttp://173.249.40.xxx/ci/info.php
CodeIgniter では動作しませんでした。controller name
http://173.249.40.xxx/ci/index.php/Welcome
CodeIgniterのアプリケーションパスは'/usr/share/nginx/html/ci/;'
何か提案してください。どうすれば修正できますか?
答え1
エラーは次のとおりです:
location /ci {
このため、 で始まる URL パスのみが で/ci
囲まれた部分によって処理されますtry_files
。これは望ましい動作ではありません。
代わりに、すべてのURLを処理し、
location / {
答え2
ファイルを編集しないことをお勧めしますnginx.conf
。gzip
と新しい include フォルダー (などinclude /etc/nginx/sites/enabled/*.conf;
) のみを編集し、元の include 行をコメント アウトして、そこに com.mywebsite.conf という名前の構成ファイルを前述のフォルダーに作成します。
これまで私が行ってきた方法は次のとおりです。
前述した新しい設定ファイルで、公式に推奨されている設定の内容をコピーします。変数をシステムに合わせて変更すれば、それが機能するはずです。
https://www.nginx.com/resources/wiki/start/topics/recipes/codeigniter/
また、ウェブサイトを/var/www/html/mywebsite