Opensourcetechブログ

OpensourcetechによるNGINX/Kubernetes/Zabbix/Neo4j/Linuxなどオープンソース技術に関するブログです。

nginx unit 1.8.0を使っていて気がついたちょっとした作法

こんにちは、LinuCエバンジェリストこと、鯨井貴博@opensourcetechです。

 igore sysoevさんと一緒

 

 nginx unit 1.8.0を使っていて気がついたちょっとした作法を記録に残しておきます。

 

 ①設定(json)が反映されない

curl -X PUTで投入しようとしても、「"error": "Failed to apply new configuration."」とか、「"error": "Invalid configuration."」とか、「"detail": "Application must have the \"type\" property set."」で怒られるパターンです。

 

なお、使用しているjsonファイルは、以下のようにnginx unitでも問題なく使用できるものです。

https://github.com/kujiraitakahiro/nginx_unit/blob/master/config_php_perl.json

[root@localhost tmp]# curl -X PUT -d @/var/tmp/config_php_perl.json --unix-socket /var/run/unit/control.sock http://localhost/config/applications/
{
"error": "Invalid configuration.",
"detail": "Application must have the \"type\" property set."
}

[root@localhost tmp]# curl -X PUT -d @/var/tmp/config_php_perl.json --unix-socket /var/run/unit/control.sock http://localhost/config/
{
"error": "Failed to apply new configuration."
}

 

 

  ①原因として考えられるもの

・JSONの記述方法が間違っている。

  ->ATOMなどEditorの力をかりることでそこそこに解決できる!

・JSONに記述されているPATH(コンテンツファイルを配置するディレクトリ)やコンテンツファイルがない

 ->これ結構はまりやすいかもしれません。

[root@localhost ~]# mkdir /www/store/
[root@localhost tmp]# vi /www/blogs/scripts/index.pl
[root@localhost tmp]# curl -X PUT -d @/var/tmp/config_php_perl.json --unix-socket /var/run/unit/control.sock http://localhost/config/
{
"success": "Reconfiguration done."
}
[root@localhost tmp]# curl --unix-socket /var/run/unit/control.sock http://localhost/config
{
"listeners": {
"*:8888": {
"pass": "applications/blogs-php"
},

"*:8887": {
"pass": "applications/blogs-perl"
}
},

"applications": {
"blogs-php": {
"type": "php",
"processes": 5,
"root": "/www/blogs/scripts",
"index": "index.php"
},

"blogs-perl": {
"type": "perl",
"processes": {
"max": 10,
"spare": 5,
"idle_timeout": 20
},

"working_directory": "/www/store/",
"script": "index.pl"
}
}
}

 

 

 ②設定が削除(DELETE)できない

curl -X DELETEで設定を削除したくても、「"error": "Invalid configuration."」とか、「"detail": "Request \"pass\" points to invalid location \"applications/blogs-php\"."」とかで怒られるパターンです。

[root@localhost tmp]# curl -X DELETE --unix-socket /var/run/unit/control.sock http://localhost/config/applications/
{
"error": "Invalid configuration.",
"detail": "Request \"pass\" points to invalid location \"applications/blogs-php\"."
}

 

 

②原因として考えられるもの

・listeners -> applicationsの順で削除する必要がある。

 ->試す限り、どうもそのようです。

  ※ドキュメントのどこかに書いてあるのかもw

[root@localhost tmp]# curl -X DELETE --unix-socket /var/run/unit/control.sock http://localhost/config/listeners/*:8888/
{
"success": "Reconfiguration done."
}
[root@localhost tmp]# curl -X DELETE --unix-socket /var/run/unit/control.sock http://localhost/config/applications/blogs-php/
{
"success": "Reconfiguration done."
}

 

 

 

www.slideshare.net

github.com

www.facebook.com

twitter.com

www.instagram.com

 

 

にほんブログ村 IT技術ブログ Linuxへ
Linux

にほんブログ村 IT技術ブログ オープンソースへ
オープンソース

 

 

Opensourcetech by Takahiro Kujirai