LoginSignup
1
1

More than 3 years have passed since last update.

【Nginx】htmlをphpで実行する

Posted at

この記事はcentos7+nginx+php7の環境で書いています。

やりたいこと

Apacheのときにこんな感じで書いていました。

httpd.conf
AddType application/x-httpd-php .html

これをnginxで設定したい。

PHP-FPM

# vi /etc/php-fpm.d/www.conf

www.conf
security.limit_extensions = .php .php3 .php4 .php5 .html

NGINX

必要なディレクティブに下記を加える。

location ~ \.html$ {
  fastcgi_split_path_info ^(.+\.php)(/.+)$;
  if (!-f $document_root$fastcgi_script_name) {
     return 404;
  }
  include /etc/nginx/fastcgi_params;
  fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
  fastcgi_index  index.html;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

最後に

再起動を忘れずに
# systemctl reload php-fpm.service
# systemctl reload nginx.service

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1