ページの作成:「'''Nginx''' とはマシンをWebマシンにするためのソフトウェア。既製品の配給は得意で非常に高速だが、組み立て配給は少し苦手…」
 
38行目: 38行目:
  http {
  http {
     server_tokens off;
     server_tokens off;
 
     server {
     server {
         server_name  hoge.com;
         server_name  hoge.com;
 
         location / {
         location / {
             root  html;
             root  html;
             index  index.php index.html index.htm;
             index  index.php index.html index.htm;
         }
         }
 
         location ~ ¥.php$ {
         location ~ ¥.php$ {
             root  html;
             root  html;

2019年2月20日 (水) 10:10時点における版

Nginx とはマシンをWebマシンにするためのソフトウェア。既製品の配給は得意で非常に高速だが、組み立て配給は少し苦手。

事前に Apache で組み立てておいた既製品を配給するウェイターとして活躍。

ソースからインストール

どのアプリにも言えることだが、ソースからインストールするとディレクトリが /usr/local/ にまとめて配置されて良い。パッケージ版だと分散される。

$ yum install pcre-devel openssl-devel    ← ビルドに必要なライブラリ。zlib は openssl-devel の依存ファイル
$ wget https://nginx.org/download/nginx-1.15.0.tar.gz
$ cd nginx-1.15.0
$ ./configure ¥
--sbin-path=/usr/sbin/nginx ¥
--with-http_ssl_module ¥
--with-http_v2_module    ← HTTP2 対応
$ make
$ sudo make install

phpinfo の表示まで

設定ファイルは極力デフォルトのまま

php-fpm の設定

# useradd --shell /sbin/nologin nginx
# yum install php-fpm
# vi /etc/php-fpm.d/www.conf
user = nginx
group = nginx
listen = /var/run/php-fpm.sock
listen.owner = nginx
listen.group = nginx
# systemctl restart php-fpm    ← 再起動で自動的に上記ソケットが作成される
# chown nginx:nginx /var/run/php-fpm.sock

Nginx の設定

修正・追記は下線部

# vi /usr/local/nginx/conf/nginx.conf
user nginx;
http {
   server_tokens off;

   server {
       server_name  hoge.com;

       location / {
           root  html;
           index  index.php index.html index.htm;
       }

       location ~ ¥.php$ {
           root  html;
           fastcgi_pass   unix:/var/run/php-fpm.sock;
           fastcgi_index  index.php;
           fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
           include        fastcgi_params;
       }
   }
}
# nginx -s reload
# firewall-cmd --add-service=http --permanent
# firewall-cmd --reload