Nginx Unit configuration cannot be applied for PHP/Laravel app. Permission issue, even with 777

huangapple go评论59阅读模式
英文:

Nginx Unit configuration cannot be applied for PHP/Laravel app. Permission issue, even with 777

问题

我正在按照这个教程操作:https://unit.nginx.org/howto/laravel/,只是进行了一些小的修改(基本上是更改了文件夹名称)。

每当我尝试使用CURL发送配置JSON时,我都会收到以下错误消息:

2023/06/15 20:01:27 [info] 5192#5192 "laravel" prototype started
2023/06/15 20:01:27 [info] 5193#5193 "laravel" application started
2023/06/15 20:01:27 [alert] 5193#5193 root realpath(/home/victor/workspace/estatutario/public/) failed (13: Permission denied)
2023/06/15 20:01:27 [notice] 5192#5192 app process 5193 exited with code 1
2023/06/15 20:01:27 [warn] 913#913 failed to start application "laravel"
2023/06/15 20:01:27 [alert] 913#913 failed to apply new conf
2023/06/15 20:01:27 [notice] 897#897 process 5192 exited with code 0

config.json

{
    "listeners": {
        "*:8003": {
            "pass": "routes"
        }
    },

    "routes": [
        {
            "match": {
                "uri": "!/index.php"
            },
            "action": {
                "share": "/home/victor/workspace/estatutario/public$uri",
                "fallback": {
                    "pass": "applications/laravel"
                }
            }
        }
    ],

    "applications": {
        "laravel": {
            "type": "php",
            "root": "/home/victor/workspace/estatutario/public/",
            "script": "index.php"
        }
    }
}

权限(为了排除故障,我已经授予了所有人的所有权限):

victor@webapps-dev:~/workspace/estatutario$ ls -la
total 384
drwxrwxrwx 13 unit   unit     4096 Jun 15 01:04 .
drwxrwxr-x 16 victor victor   4096 Jun 15 19:53 ..
drwxrwxrwx  7 unit   unit     4096 Jun 15 01:00 app
-rwxrwxrwx  1 unit   unit     1686 Jun 15 01:00 artisan
drwxrwxrwx  3 unit   unit     4096 Jun 15 01:00 bootstrap
(...)

PWD:

victor@webapps-dev:~/workspace/estatutario$ pwd
/home/victor/workspace/estatutario

运行Unit的用户:

victor@webapps-dev:~$ ps -ef | grep unit
root         897       1  0 19:15 ?        00:00:00 unit: main v1.30.0 [/usr/sbin/unitd]
unit         912     897  0 19:15 ?        00:00:00 unit: controller
unit         913     897  0 19:15 ?        00:00:00 unit: router
victor      5559    1507  0 20:10 pts/0    00:00:00 grep --color=auto unit

我已经多次检查了文件夹名称,甚至授予了777权限。(尽管用户似乎是正确的 - unit)。

您认为为什么我仍然收到这个错误消息?

<details>
<summary>英文:</summary>

I&#39;m following this how-to: https://unit.nginx.org/howto/laravel/, with small modifications (basically changed the folder name).

Whenever I try to send the configuration JSON with CURL, I get this error message:

    2023/06/15 20:01:27 [info] 5192#5192 &quot;laravel&quot; prototype started
    2023/06/15 20:01:27 [info] 5193#5193 &quot;laravel&quot; application started
    2023/06/15 20:01:27 [alert] 5193#5193 root realpath(/home/victor/workspace/estatutario/public/) failed (13: Permission denied)
    2023/06/15 20:01:27 [notice] 5192#5192 app process 5193 exited with code 1
    2023/06/15 20:01:27 [warn] 913#913 failed to start application &quot;laravel&quot;
    2023/06/15 20:01:27 [alert] 913#913 failed to apply new conf
    2023/06/15 20:01:27 [notice] 897#897 process 5192 exited with code 0


config.json

    {
		&quot;listeners&quot;: {
			&quot;*:8003&quot;: {
				&quot;pass&quot;: &quot;routes&quot;
			}
		},

		&quot;routes&quot;: [
			{
				&quot;match&quot;: {
					&quot;uri&quot;: &quot;!/index.php&quot;
				},
				&quot;action&quot;: {
					&quot;share&quot;: &quot;/home/victor/workspace/estatutario/public$uri&quot;,
					&quot;fallback&quot;: {
						&quot;pass&quot;: &quot;applications/laravel&quot;
					}
				}
			}
		],

		&quot;applications&quot;: {
			&quot;laravel&quot;: {
				&quot;type&quot;: &quot;php&quot;,
				&quot;root&quot;: &quot;/home/victor/workspace/estatutario/public/&quot;,
				&quot;script&quot;: &quot;index.php&quot;
			}
		}
    }


Permissions (to troubleshoot, I gave all permissions to everybody):

	victor@webapps-dev:~/workspace/estatutario$ ls -la
	total 384
	drwxrwxrwx 13 unit   unit     4096 Jun 15 01:04 .
	drwxrwxr-x 16 victor victor   4096 Jun 15 19:53 ..
	drwxrwxrwx  7 unit   unit     4096 Jun 15 01:00 app
	-rwxrwxrwx  1 unit   unit     1686 Jun 15 01:00 artisan
	drwxrwxrwx  3 unit   unit     4096 Jun 15 01:00 bootstrap
	(...)

PWD:

    victor@webapps-dev:~/workspace/estatutario$ pwd
    /home/victor/workspace/estatutario


User running Unit:

    victor@webapps-dev:~$ ps -ef | grep unit
    root         897       1  0 19:15 ?        00:00:00 unit: main v1.30.0 [/usr/sbin/unitd]
    unit         912     897  0 19:15 ?        00:00:00 unit: controller
    unit         913     897  0 19:15 ?        00:00:00 unit: router
    victor      5559    1507  0 20:10 pts/0    00:00:00 grep --color=auto unit

I&#39;ve double-checked the folder name and even gave 777 permissions. (Even though the user seems correct - unit).

Any thoughts why I&#39;m still getting this error message?

</details>


# 答案1
**得分**: 0

Ok,经过对类似问题的一些研究(https://stackoverflow.com/questions/25774999/nginx-stat-failed-13-permission-denied),我发现Unit的行为与Nginx相同。

因此,之前的问题描述的问题/解决方案也适用。
尽管我将我的项目的根目录更改为unit:unit,但父目录仍然是我的(victor:victor)。

/home/victor/workspace/myproject &lt;--- unit:unit
/home/victor/workspace/ &lt;--- victor:victor
/home/victor/ &lt;--- victor:victor

Nginx似乎需要从根目录一直到要提供的文件夹都具有“x”权限。我可以为unit提供这些权限,或者从另一个目录提供服务。

所以我决定从我的家目录外提供服务。/apps/myproject(unit:unit)

<details>
<summary>英文:</summary>

Ok, after some research on a similar issue (https://stackoverflow.com/questions/25774999/nginx-stat-failed-13-permission-denied) I found that Unit acts the same way as Nginx. 

So the problem / solution described on the previous question also applied.
Even though I chowned the my project&#39;s root folder to unit:unit, the parent folder was still mine (victor:victor).

    /home/victor/workspace/myproject &lt;--- unit:unit
    /home/victor/workspace/ &lt;--- victor:victor
    /home/victor/ &lt;--- victor:victor

Nginx seems to need to have &quot;x&quot; permission from the root all the way to the folder you want to serve. I could either give unit those permissions or serve it from another directory.

So I decided to serve from outside my home. /apps/myproject (unit:unit)

</details>



huangapple
  • 本文由 发表于 2023年6月16日 04:09:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76485194.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定