Nginx php fpm html files

19 Сен 2017 15:09:12 | 2 комментария

Как заставить nginx выполнять php-код в html файлах ?

Есть сервер nginx и php5-fpm в качестве fastcgi-бэкенда.
Необходимо настроить эту связку на выполнение php-кода из .html (.htm, .phtml) файлов.

Исходные данные: Debian 8.9 (jessie), nginx 1.13.5, php5-fpm 5.6.30

Необходимо выполнить ряд шагов:

1. nginx должен передавать html-файлы fastcgi-бэкенду. Для этого нужно изменить location, где прописана обработка php-файлов, либо добавить новый location:

Например, файл /etc/nginx/sites-available/mysite.ru.vhost приводим к виду:

listen XX.XX.XX.XX:80; server_name mysite.ru; index index.php index.html index.htm index.phtml; set $fastcgipass unix:/var/lib/php5-fpm/web1.sock; location / < try_files $uri $uri/ /index.php; >location ~ \.(php|htm|html|phtml)$ < try_files $uri = 404; include /etc/nginx/fastcgi_params; fastcgi_pass $fastcgipass; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; >

Обратите внимание на location ~ \.(php|htm|html|phtml)$

2. php5-fpm по-умолчанию отказывается обрабатывать файлы оканчивающиеся не на .php
Чтобы это исправить нужно в файле /etc/php5/php-fpm.conf (или же в файле конфигурации вашего пула, если у вас есть деление на пулы) добавить строку security.limit_extensions.

Например в файле пула /etc/php5/fpm/pool.d/web1.conf

[web1] listen = /var/lib/php5-fpm/web1.sock . security.limit_extensions = .php .html .htm .phtml .

P.S. Если используется панель хостинга ISPConfig, то файл пула необходимо защитить от изменений иначе панель его перезапишет и наши настройки потеряются, для защиты поставим аттрибут immutable на файл:

chattr +i /etc/php5/fpm/pool.d/web1.conf

На этом все, до скорых встреч. Если у Вас возникли вопросы или Вы хотите чтобы я помог Вам, то Вы всегда можете связаться со мной разными доступными способами.

Источник

Nginx php fpm html files

  • The basics of TOGAF certification and some ways to prepare TOGAF offers architects a chance to learn the principles behind implementing an enterprise-grade software architecture, including.
  • Haskell vs. PureScript: The difference is complexity Haskell and PureScript each provide their own unique development advantages, so how should developers choose between these two .
  • A quick intro to the MACH architecture strategy While not particularly prescriptive, alignment with a MACH architecture strategy can help software teams ensure application .
  • Postman API platform will use Akita to tame rogue endpoints Akita’s discovery and observability will feed undocumented APIs into Postman’s design and testing framework to bring them into .
  • How to make use of specification-based test techniques Specification-based techniques can play a role in efficient test coverage. Choosing the right techniques can ensure thorough .
  • GitHub Copilot Chat aims to replace Googling for devs GitHub’s public beta of Copilot Chat rolls out GPT-4 integration that embeds a chat assistant into Visual Studio, but concerns .
  • Navigate multi-cloud billing challenges Keeping track of cloud bills from multiple clouds or accounts can be complex. Learn how to identify multi-cloud billing .
  • 5 Google Cloud cost optimization best practices Cost is always a top priority for enterprises. For those considering Google Cloud, or current users, discover these optimization .
  • How to create and manage Amazon EBS snapshots via AWS CLI EBS snapshots are an essential part of any data backup and recovery strategy in EC2-based deployments. Become familiar with how .
  • BrightTALK @ Black Hat USA 2022 BrightTALK’s virtual experience at Black Hat 2022 included live-streamed conversations with experts and researchers about the .
  • The latest from Black Hat USA 2023 Use this guide to Black Hat USA 2023 to keep up on breaking news and trending topics and to read expert insights on one of the .
  • API keys: Weaknesses and security best practices API keys are not a replacement for API security. They only offer a first step in authentication — and they require additional .
  • AWS Control Tower aims to simplify multi-account management Many organizations struggle to manage their vast collection of AWS accounts, but Control Tower can help. The service automates .
  • Break down the Amazon EKS pricing model There are several important variables within the Amazon EKS pricing model. Dig into the numbers to ensure you deploy the service .
  • Compare EKS vs. self-managed Kubernetes on AWS AWS users face a choice when deploying Kubernetes: run it themselves on EC2 or let Amazon do the heavy lifting with EKS. See .

Источник

Is it possible to serve static html from php-fpm?

I’ve dockerised a wordpress application, now I’m being a purist and don’t want to include nginx in the docker container and don’t want to share any state between the nginx container and php-fpm container. I want to run php-fpm as a standalone webserver (like unicorn in ruby or gunicorn in python) serving all the content (html, css and images) for the wordpress site. And run a nginx reverse proxy in front off it (caching static content). That way I can keep the separation of concerns and I don’t have nginx forwarding traffic to and nginx server. The default configuration for php-fpm only allows php files to be processed. Can the php-fpm conf that be changed? How? Is it a good idea?

2 Answers 2

You could, but the performance would be terrible, since everything would go through the PHP interpreter. This would also introduce an obvious, massive security problem.

This is exactly the sort of scenario in which you should be using shared data volumes.

PHP should run coden only in and .php files, shouldn’t? Or FPM will interpret everything including .jpg or .txt?

There is no reason why performance would be terrible. If you need to protect access to a file, it’s normal to check access by PHP and if it’s a public file then PHP application should set cache HTTP headers so any cache proxy could improve perfs.

@Charles-ÉdouardCoste Even if you check access in PHP code, you generally would not have PHP serve the file itself. It’s not very fast at that. You would pass that back to Apache or nginx.

It is quite easy to add as a comment into GIF files. Then you simply let the website display the picture and you are in.

Источник

Читайте также:  Php post file base64
Оцените статью