LNMP prompt solution to the problem File not found

This article describes about the solution to the LNMP prompt File not found the problem, the paper sample code described in great detail, has a certain reference value of learning for all of us to learn or work, we need friends below with small edited together to learn learn it.
Foreword

Under normal circumstances each virtual host is a site, the site is generally accessible through the domain name. Recently when configuring LNMP (Linux Nginx MariaDB Php-fpm) has encountered a problem:

Home has always been to enhance access File not found.

After the final settlement is a summary: Web site root permissions problem.

Due

To talk about the causes of things. I used the system is Manjaro Linux system. So with a single command installed LNMP environment: sudo pacman -S mariadb nginx php. At first, I put the symfony project in my home directory, that is ~ / projects. Then I copy from the official symfony nginx configuration file symfony.conf, in the / etc / nginx / sites-available under the directory, and then change the root parameter for the / home / lrcn / projects / symfony / public, and changed fastcgi_pass parameters unix: /run/php-fpm/php-fpm.sock. Well, run sudo nginx -t test passed, and then restart nginx.

But the problem came, I entered symfony.dev browser (Add a hosts as 127.0.0.1 symfony.dev) always prompts File not found. Even if I set the site directory 777 is not OK! This question had been nagging me for a day! Really is the heart almost exploded. Finally, I took a deep breath and think about this question. The answer turned out to be searched in the Internet resources.

It is explained. PHP-FPM program requires a user and user groups to run the program. The users and groups on my project files must have rx permission. Some directories must have rwx permissions, such as upload, log directory, and so on. Nginx program also requires a user, the user can also file for this project has rx permissions.

Solution

Since my nginx default user is http, so I want to change it to nginx, and nginx join the user group www. At the same time, I put the php-fpm instead of user www, user groups have changed www.

1) Create a user

sudo useradd -s / sbin / nologin www # www user to create, and it will automatically create a www user group sudo gpasswd -a nginx www # nginx user to join the user group to www
2) modify the configuration file

Since I am here just relevant configuration file permissions, and the remaining configure itself also need to adjust

grep " [ ;]" /etc/php/php-fpm.d/www.conf# modify the time just modifying user, group, listen.owner, listen.group, the rest are the default configuration [www] user = wwwgroup = wwwlisten = /run/php-fpm/php-fpm.socklisten.owner = wwwlisten.group = wwwlisten.mode = 0660pm = dynamicpm.max_children = 5 pm.start_servers = 2 pm.min_spare_servers = 1 pm.max_spare_servers = 3 # / etc / nginx /nginx.conf# writing the first line remaining unchanged user nginx www;

3) modify the project file permissions

This step I found a very strange question, if I have a website directory placed lrcn user's home directory, then, www users still can not access the project file, even though I ~ / projects set to chown www: www ~ / projects - R, but do not work, run the test command sudo -u www stat ~ / projects / symfony still prompts do not have permission. I think, should be the owner / home / lrcn directory is lrcn, even though I changed it to a subdirectory of projects www: www, is not accessible. This is reasonable. So, I turn on the project directory under / var / www directory, then run sudo -u www stat / var / www , get a normal result: date of birth from the name

[Lrcn @ lrcn-pc nginx] $ sudo -u www stat / var / www [sudo] lrcn password: file: / var / www Size: 4096: 8 IO block: 4096 directory device: 801h / 2049d Inode: 3671064 hard Links: 3 rights: (2775 / drwxrwsr-x) Uid :( 1000 / lrcn) Gid :( 1001 / lrcn) Last visit: 2017-12-1000: 40: 04.274947995 +0800 recent changes: 2017-12-10 00: 41: 34.772321160 +0800 recent changes: 2017-12-1010: 51: 15.811999323 +0800 creation time

Guess you like

Origin blog.csdn.net/sakura379/article/details/93471392