serverapps:nginx:phpfpm
差分
このページの2つのバージョン間の差分を表示します。
| 両方とも前のリビジョン前のリビジョン次のリビジョン | 前のリビジョン | ||
| serverapps:nginx:phpfpm [2017/12/27 11:08] – [php-extensions] hayashi | serverapps:nginx:phpfpm [2023/08/27 07:35] (現在) – [/usr/local/etc/php-fpm.d/www.conf] hayashi | ||
|---|---|---|---|
| 行 1: | 行 1: | ||
| + | ====== NGiNX + php-fpm ====== | ||
| + | phpを動作させるに当たってはphpに同梱されているphp-FPM(FastCGI Process Manager)を利用する。 | ||
| + | |||
| + | ===== Install ===== | ||
| + | |||
| + | ==== NGiNX ==== | ||
| + | オプションの設定があるのでportsからインストールする。((perlが一緒にインストールされるので、先にpkgで入れておくのが吉))\\ | ||
| + | 2017.12.27:GEOIP、IMAGE_FILTER、PERL以外は最初からONになってるのでPKGでもOK | ||
| + | < | ||
| + | # cd / | ||
| + | # make config | ||
| + | [X] : HTTP_ADDITION_MODULE | ||
| + | [X] : HTTP_CACHE_MODULE | ||
| + | [X] : HTTP_GEOIP_MODULE | ||
| + | [X] : HTTP_GZIP_STATIC_MODULE | ||
| + | [X] : HTTP_IMAGE_FILTER_MODULE | ||
| + | [X] : HTTP_PERL_MODULE | ||
| + | [X] : HTTP_REALIP_MODULE | ||
| + | [X] : HTTP_REWRITE_MODULE | ||
| + | [X] : HTTP_SSL | ||
| + | [X] : HTTP_STATUS_MODULE | ||
| + | # make install | ||
| + | # make clean | ||
| + | </ | ||
| + | |||
| + | # pkg lock nginx | ||
| + | ==== php ==== | ||
| + | < | ||
| + | 2017.12.27: | ||
| + | |||
| + | # pkg install php71 | ||
| + | |||
| + | ↓ここは古い | ||
| + | < | ||
| + | # cd / | ||
| + | # make config | ||
| + | [X] : FPM | ||
| + | # make install | ||
| + | # make clean | ||
| + | </ | ||
| + | |||
| + | # pkg lock php56 | ||
| + | |||
| + | ==== php-extensions ==== | ||
| + | |||
| + | pkg install php71-extensions | ||
| + | |||
| + | ===== 設定 ===== | ||
| + | ==== / | ||
| + | |||
| + | とりあえずこんな感じ。((/ | ||
| + | < | ||
| + | date.timezone = Asia/ | ||
| + | memory_limit = 32M | ||
| + | upload_max_filesize = 10M | ||
| + | post_max_size = 20M | ||
| + | expose_php = off <= phpのバージョンをheaderに表示しない | ||
| + | </ | ||
| + | |||
| + | ==== / | ||
| + | |||
| + | < | ||
| + | [global] | ||
| + | events.mechanism = kqueue | ||
| + | ... | ||
| + | include=/ | ||
| + | </ | ||
| + | |||
| + | ==== / | ||
| + | |||
| + | < | ||
| + | [www] | ||
| + | user = www | ||
| + | group = www | ||
| + | listen = / | ||
| + | listen.owner = www <= 設定しないと / | ||
| + | listen.group = www <= | ||
| + | listen.mode = 0666 <= | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | ==== / | ||
| + | |||
| + | < | ||
| + | user www www; | ||
| + | worker_processes | ||
| + | worker_cpu_affinity | ||
| + | worker_priority | ||
| + | # | ||
| + | error_log | ||
| + | |||
| + | pid / | ||
| + | |||
| + | events { | ||
| + | multi_accept | ||
| + | worker_connections | ||
| + | accept_mutex on; | ||
| + | accept_mutex_delay | ||
| + | } | ||
| + | |||
| + | http { | ||
| + | include | ||
| + | include | ||
| + | include | ||
| + | |||
| + | include | ||
| + | default_type | ||
| + | |||
| + | access_log | ||
| + | |||
| + | include sites/ | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ==== / | ||
| + | ((http節でinclude)) | ||
| + | |||
| + | < | ||
| + | client_body_timeout | ||
| + | client_header_timeout | ||
| + | keepalive_timeout | ||
| + | send_timeout | ||
| + | charset | ||
| + | gzip on; | ||
| + | gzip_static | ||
| + | gzip_proxied | ||
| + | ignore_invalid_headers | ||
| + | keepalive_requests | ||
| + | keepalive_disable | ||
| + | max_ranges | ||
| + | msie_padding | ||
| + | open_file_cache | ||
| + | open_file_cache_errors | ||
| + | open_file_cache_min_uses | ||
| + | open_file_cache_valid | ||
| + | output_buffers | ||
| + | postpone_output | ||
| + | read_ahead | ||
| + | recursive_error_pages | ||
| + | reset_timedout_connection on; | ||
| + | sendfile | ||
| + | server_tokens | ||
| + | server_name_in_redirect | ||
| + | source_charset | ||
| + | tcp_nodelay | ||
| + | tcp_nopush | ||
| + | gzip_disable | ||
| + | limit_req_zone | ||
| + | log_format | ||
| + | </ | ||
| + | |||
| + | ==== / | ||
| + | 以下の設定でデフォルトでは接続しなくなる | ||
| + | < | ||
| + | server { | ||
| + | listen 80 default_server; | ||
| + | return 444; <= コネクションクローズ | ||
| + | } | ||
| + | </ | ||
| + | ==== / | ||
| + | < | ||
| + | server { | ||
| + | server_name example.com www.example.com; | ||
| + | # add_header | ||
| + | add_header | ||
| + | add_header | ||
| + | add_header | ||
| + | limit_req | ||
| + | <= gulag の定義はconf.d/ | ||
| + | expires | ||
| + | |||
| + | listen 80; | ||
| + | listen 443 ssl; <= SSL関連 | ||
| + | include conf.d/ | ||
| + | |||
| + | root / | ||
| + | index index.html index.htm index.php; | ||
| + | |||
| + | location = / | ||
| + | |||
| + | location ~* \.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)? | ||
| + | |||
| + | location ~ /\. { | ||
| + | deny all; | ||
| + | access_log off; | ||
| + | log_not_found off; | ||
| + | } | ||
| + | |||
| + | location / { | ||
| + | root / | ||
| + | try_files $uri $uri/ / | ||
| + | } | ||
| + | |||
| + | |||
| + | location ~ \.php$ { include conf.d/ | ||
| + | |||
| + | error_page | ||
| + | location = /50x.html { root / | ||
| + | } | ||
| + | </ | ||
| + | ==== / | ||
| + | |||
| + | < | ||
| + | ssl_certificate / | ||
| + | ssl_certificate_key / | ||
| + | ssl_dhparam / | ||
| + | ssl_protocols TLSv1 TLSv1.1 TLSv1.2; | ||
| + | ssl_ciphers " | ||
| + | ssl_prefer_server_ciphers on; | ||
| + | ssl_session_cache shared: | ||
| + | ssl_session_timeout 10m; | ||
| + | </ | ||
| + | |||
| + | ==== / | ||
| + | |||
| + | < | ||
| + | fastcgi_pass unix:/ | ||
| + | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | ||
| + | try_files | ||
| + | fastcgi_split_path_info | ||
| + | fastcgi_index | ||
| + | fastcgi_intercept_errors | ||
| + | fastcgi_ignore_client_abort | ||
| + | fastcgi_connect_timeout | ||
| + | fastcgi_send_timeout | ||
| + | fastcgi_read_timeout | ||
| + | fastcgi_buffer_size | ||
| + | fastcgi_buffers | ||
| + | fastcgi_busy_buffers_size | ||
| + | fastcgi_temp_file_write_size | ||
| + | # | ||
| + | # | ||
| + | include fastcgi_params; | ||
| + | </ | ||
| + | ===== 起動 ===== | ||
| + | ==== / | ||
| + | php_fpm_enable=" | ||
| + | nginx_enable=" | ||
| + | |||
| + | ==== チェック ==== | ||
| + | # service nginx configtest | ||
| + | Performing sanity check on nginx configuration: | ||
| + | nginx: the configuration file / | ||
| + | nginx: configuration file / | ||
| + | | ||
| + | ==== チェック用のページを作る ==== | ||
| + | |||
| + | # sh -c 'echo "<? | ||
| + | |||
| + | ==== 起動 ==== | ||
| + | |||
| + | # service php-fpm restart | ||
| + | # service nginx restart | ||
| + | ===== 参考 ===== | ||
| + | [[http:// | ||
| + | |||
| + | [[http:// | ||
