お世話になります、質問をご覧いただきありがとうございます。
前提・実現したいこと
さくらのVPS上にcodeigniter3のサーバーを構築したいのですが、codeigniterのルーティングが効かずに困っているため、何か問題点があればご指摘いただけると幸いです。
発生している問題・エラーメッセージ
ルートパスや http://.../login などすべてのURLで404になってしまいます。
404 not found
/var/log/nginx/error.log
2019/01/12 07:34:58 [error] 9104#9104: *694 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: **.***.***.***, server: ***.***.**.***, request: "GET /mysql/mysqlmanager/index.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:",
/var/log/php-fpm/error.log
[11-Jan-2019 09:15:53] NOTICE: Terminating ... [11-Jan-2019 09:15:53] NOTICE: exiting, bye-bye! [11-Jan-2019 09:15:53] NOTICE: fpm is running, pid 5667 [11-Jan-2019 09:15:53] NOTICE: ready to handle connections [11-Jan-2019 09:15:53] NOTICE: systemd monitor interval set to 10000ms [11-Jan-2019 10:22:21] NOTICE: Terminating ... [11-Jan-2019 10:22:21] NOTICE: exiting, bye-bye!
該当のソースコード
長くなってしまい申し訳ありませんが、php-fpmとnginxの設定ファイルをすべて記載いたします。
・/etc/nginx/nginx.conf
user www-data; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; gzip on; gzip_http_version 1.0; gzip_disable "msie6"; gzip_proxied any; gzip_min_length 1024; gzip_comp_level 6; gzip_types image/png image/gif image/jpeg text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript; gunzip on; open_file_cache max=100000 inactive=20s; open_file_cache_valid 30s; open_file_cache_min_uses 2; open_file_cache_errors on; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; index index.php index.htm; server { listen 80 default_server; listen [::]:80 default_server; server_name localhost; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { add_header my_string 'start'; # <- これを追加 add_header my_document_root $document_root; # <- これを追加 add_header fastcgi_script_name $fastcgi_script_name; # <- これを追加 add_header my_fastcgi_path_info $fastcgi_path_info; # <- これを追加 add_header my_string_2 ‘end’; # <- これを追加 } # redirect server error pages to the static page /40x.html # error_page 404 /404.html; location = /40x.html { } # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ .php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ .php$ { fastcgi_index index.php; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; #fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location /health.html { access_log off; break; } } }
・/etc/nginx/conf.d/default.conf
server { listen 80; server_name ***.***.**.*** ; # まだドメインを紐付けていないためIPアドレスを記載しています #charset koi8-r; #access_log /var/log/nginx/host.access.log main; error_log /var/log/nginx/error.log warn; root /codeigniterのroot/public_html; location / { root /codeigniterのroot/public_html; index index.php index.html; #try_files $uri $uri/ /index.php; try_files $uri /index.php?$query_string; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 location ~ .php$ { fastcgi_index index.php; root /codeigniterのroot/public_html; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param CI_ENV production; fastcgi_param STORE_FOLDER /var/www/html/store; include fastcgi_params; } }
・"/etc/php-fpm.d/www.conf"
; Start a new pool named 'www'. ; the variable $pool can we used in any directive and will be replaced by the ; pool name ('www' here) [www] ; Per pool prefix ; It only applies on the following directives: ; - 'access.log' ; - 'slowlog' ; - 'listen' (unixsocket) ; - 'chroot' ; - 'chdir' ; - 'php_values' ; - 'php_admin_values' ; When not set, the global prefix (or @php_fpm_prefix@) applies instead. ; Note: This directive can also be relative to the global prefix. ; Default Value: none ;prefix = /path/to/pools/$pool ; Unix user/group of processes ; Note: The user is mandatory. If the group is not set, the default user's group ; will be used. ; RPM: apache user chosen to provide access to the same directories as httpd user = www-data ; RPM: Keep a group allowed to write in log dir. group = www-data security.limit_extensions = .php .html ; The address on which to accept FastCGI requests. ; Valid syntaxes are: ; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on ; a specific port; ; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on ; a specific port; ; 'port' - to listen on a TCP socket to all addresses ; (IPv6 and IPv4-mapped) on a specific port; ; '/path/to/unix/socket' - to listen on a unix socket. ; Note: This value is mandatory. listen = /var/run/php-fpm/php-fpm.sock ; Set listen(2) backlog. ; Default Value: 511 ;listen.backlog = 511 ; Set permissions for unix socket, if one is used. In Linux, read/write ; permissions must be set in order to allow connections from a web server. ; Default Values: user and group are set as the running user ; mode is set to 0660 listen.owner = www-data listen.group = www-data listen.mode = 0660 ; When POSIX Access Control Lists are supported you can set them using ; these options, value is a comma separated list of user/group names. ; When set, listen.owner and listen.group are ignored ;listen.acl_users = apache,nginx ;listen.acl_groups =
試したこと
切り分けとして、PHP-FPMがUNIXソケットで動いていることを確認しております。
netstat -a --unix
を打つと、 unix 2 [ ACC ] STREAM LISTENING 651214 /var/run/php-fpm/php-fpm.sock
が出てきました。
/codeigniterのパス/public_html/index.php に phpinfo()
を打つとphp-fpmが動作していることは確認できております。
また、パーミッション周りも確認していまして、ディレクトリは644 ファイルは755に設定しております。
以上の結果から、問題はnginxからphp-fpmを上手く呼び出せていないのではないかと考えております。
補足情報(FW/ツールのバージョンなど)
・PHP7.033
・nginx: 1.15
・CentOS7
どうぞよろしくお願いいたします。

回答3件
あなたの回答
tips
プレビュー