- 投稿日:
確認環境
Env | Ver |
---|---|
OS | Ubuntu 20.04.4 LTS |
PHP | 8.0.29 |
nginx | 1.18.0 |
手順
php-fpmの導入
sudo apt install php8.0-fpm
sudo sed -i -e 's/;listen.mode = 0660/listen.mode = 0666/' /etc/php/8.0/fpm/pool.d/www.conf
sudo service php8.0-fpm start
nginxの設定
設定ファイルを開きPHPを動かす設定を書く
location ~ ^/.*$ {
root /path/to/www;
fastcgi_pass unix:/run/php/php8.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
- 投稿日:
ローカル環境用の開発ドメインをhttps化する時に使えるやつ
例えばローカル環境に複数のサービスがいて、それぞれをhttps://*.example.com/
のようなドメインで管理したい時に使える
確認環境
同じことをすればLinuxとかでも応用できると思う
Env | Ver |
---|---|
nginx | 1.19.8 |
mkcert | 1.4.3 |
Windows 10 Pro | 19043.1415 |
手順
- mkcert の導入とワイルドカード証明書の作成
choco install mkcert # mkcertを認証局として登録 mkcert -install # 証明書を作成するドメインを列挙 mkcert example.test *.example.test mv _wildcard.example.com+1.* C:/nginx/conf/.ssl/
nginxの設定に証明書を記載
server { server_name dev.example.com; listen 443 ssl; ssl_certificate ssl/_wildcard.example.com+1.pem; ssl_certificate_key ssl/_wildcard.example.com+1-key.pem; ... }
- 投稿日:
Proxy headerを設定しないとiOS Safari環境で上手くアクセスできないケースがあるのでやる設定
確認環境
Env | Ver |
---|---|
nginx | 1.19.8 |
サンプルコード
httpセクション
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
リバースプロキシ設定
location @prox {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass https://example.com;
}
- 投稿日:
確認環境
Env | Ver |
---|---|
Windows | 10 pro |
PHP | 8.0.2 NTS Visual C++ 2019 x64 |
nginx | 1.19.8 |
手順
nginx.conf
を開きFastCGI server listening on 127.0.0.1:9000
辺りに次の設定をする
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME C:/nginx/html/$fastcgi_script_name;
include fastcgi_params;
}
- 設定したフォルダに
.php
ファイルを配置 nginx
を起動php-cgi.exe -b 127.0.0.1:9000
.php
ファイルにアクセス
サービス化する
- winswを使うとできるらしい