I have got problems with nginx http autorisation - php

I take project from job to home with all of their configuration and with htpasswd.pwd file.
At job all works great, at home i see internal 500 error.
In logs I have got this:
2014/08/03 21:06:53 [crit] 8543#0: *15 open() "/etc/nginx/htpasswd.pwd" failed (13: Permission denied), client: 127.0.0.1, server: mylocal.dev, request: "GET / HTTP/1.1", host: "mylocal.dev"
and here is my namei -l result:
root#laptop:/home/root# namei -l /etc/nginx/htpasswd.pwd
f: /etc/nginx/htpasswd.pwd
drwxr-xr-x root root /
drwxr-xr-x root root etc
drw-r--r-- myuser myuser nginx
-rwxr-xr-x myuser myuser htpasswd.pwd
what i must to do?

Set chmod of htpasswd.pwd to 0755, if this doesn't work set it to 0777.

Related

Nginx php7.4 permission denied

I have stacked with permission denied on my php site. I have tried lot of different configuration but no luck. I am using nginx 1.16, php 7.4 centos . Right now I have disable SELinux and rest configuration:
Nginx runs with user nginx.
Site permissions folders have 775 permissions and files 664. For both of these owner is my user and group is nginx.
Php-fpm :
user: myuser,
group: nginx,
owneruser: nginx,
ownergroup: nginx,
mode : 0660
I am trying to access a simple test.php file that echoes "hello".
My browser shows a white screen with 404 error and the log files show permission denied.
UPDATE
I tested with a test.html page and still got permission denied so I guess it is not something with php but something with nginx.
Below are excerpts from access and error.log accordingly:
Access log excerpt:
176.92.20.33 - - [17/Dec/2020:06:56:32 +0200] "GET /test.html HTTP/1.1" 404 153 "-" "Mozilla/5.0 (Android 10; Mobile; rv:84.0) Gecko/84.0 Firefox/84.0" "-"
Error Log excerpt:
2020/12/17 06:56:32 [crit] 1152#0: *3 stat() "/home/xxxx/www/test.html" failed (13: Permission denied), client: 176.92.20.33, server: acropolismuseumkids.gr, request: "GET /test.html HTTP/1.1", host: "xxxxx"
2020/12/17 06:56:32 [crit] 1152#0: *3 stat() "/home/xxxxx/www/index.php" failed (13: Permission denied), client: 176.92.20.33, server: xxxxxx, request: "GET /test.html HTTP/1.1", host: "xxxxx"
2020/12/17 06:56:32 [crit] 1152#0: *3 stat() "/home/xxxxx/www/404.html" failed (13: Permission denied), client: 176.92.20.33, server: xxxxxx, request: "GET /test.html HTTP/1.1", host: "xxxxx"
2020/12/17 06:56:32 [crit] 1152#0: *3 stat() "/home/xxxxx/www/404.html" failed (13: Permission denied), client: 176.92.20.33, server: xxxxx, request: "GET /test.html HTTP/1.1", host: "xxxxxx"
2020/12/17 06:56:32 [crit] 1152#0: *3 stat() "/home/xxxxx/www/index.php" failed (13: Permission denied), client: 176.92.20.33, server: xxxxx, request: "GET /test.html HTTP/1.1", host: "xxxxx"
Any help is appreciated.
Well It seems I had made a studipd mistake.
I has misstyped the cgi gateway on nginx and php-fpm configuration files.
These two should be the same.

Apache / PHP error_log location in Docker

My PHP script has an error. For example, this shows this on the screen:
Warning: require(/var/www/foo.php): failed to open stream:
Where can I find this in the logs?
I tried docker logs containerName, but it only shows access logs. E.g.,
192.168.2.1 - - [17/Mar/2019:10:00:00 +0000] "GET / HTTP/1.1" 200 505 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64)...
It doesn't show the PHP error above.
Going in the Apache logs folder inside the container via docker exec shows the following:
ls -hltra /var/log/apache2
total 0
lrwxrwxrwx. 1 www-data www-data 11 Feb 6 04:42 other_vhosts_access.log -> /dev/stdout
lrwxrwxrwx. 1 www-data www-data 11 Feb 6 04:42 error.log -> /dev/stderr
lrwxrwxrwx. 1 www-data www-data 11 Feb 6 04:42 access.log -> /dev/stdout
I'm not even sure if this is where the PHP logs are at, but I can't view them.
Where can I find the Apache/PHP error logs in Docker?
Ensure that you have the following inside php.ini in order to be able to see the errors using docker logs -f containerName as in general, sending the logs to /dev/stdout and /dev/stderr makes you able to receive it through docker logs:
log_errors = On
error_log = /dev/stderr
To only see PHP logs, try:
docker logs -f [containerName] >/dev/null
To see all logs, try:
docker logs -f [containerName]

nginx permission denied error on alpine drupal 8 docker image

We have created a container from this image: https://github.com/bytepark/alpine-drupal8 and connected our drupal 8 site. It seems to load just fine, but when we go to add a new field to a content-type, it fails with no error in the page. Checking /var/log/nginx/error.log I see:
2016/09/16 20:58:11 [crit] 13685#13685: *26 open()
"/var/lib/nginx/tmp/fastcgi/7/00/0000000007" failed (13: Permission
denied) while reading upstream, client: x.x.x.x, server: _, request:
"POST
/admin/structure/views/ajax/add-handler/content/page_1/field?_wrapper_format=drupal_ajax
HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm.sock:", host:
"x.x.x.x:8080", referrer:
"http://x.x.x.x:8080/admin/structure/views/view/content"
I have tried setting permissions to 777 on /var/lib/nginx and subfolders but that has no effect:
root#:/usr/share/nginx/html# ls -l /var/lib/nginx/
total 8
drwxrwxrwx 2 root root 4096 Sep 16 20:11 html
lrwxrwxrwx 1 root root 14 Aug 24 13:27 logs -> /var/log/nginx
lrwxrwxrwx 1 root root 22 Aug 24 13:27 modules -> /usr/lib/nginx/modules
lrwxrwxrwx 1 root root 10 Aug 24 13:27 run -> /run/nginx
drwxrwxrwx 6 nginx nginx 4096 Sep 16 20:04 tmp
root#:/usr/share/nginx/html# ls -l /var/lib/nginx/tmp
total 16
drwxrwxrwx 2 nginx nginx 4096 Sep 16 20:04 fastcgi
drwxrwxrwx 2 nginx nginx 4096 Sep 16 20:04 proxy
drwxrwxrwx 2 nginx nginx 4096 Sep 16 20:04 scgi
drwxrwxrwx 2 nginx nginx 4096 Sep 16 20:04 uwsgi
I've tried lots of different solutions from google but nothing seems to make any difference, is there something I am missing here?

Nginx PHP5.6 permission eror

I am getting the following error in my Nginx error.log file, what do I need to do to prevent this from happening?
2016/06/28 09:43:37 [crit] 1631#0: *1 connect() to
unix:/run/php/php5.6 fpm.sock failed (13: Permission denied) while
connecting to upstream, client: 192.168.56.1, server: my-vm, request:
"GET / HTTP/1.1", upstream:
"fastcgi://unix:/run/php/php5.6-fpm.sock:", $host: "my-vm-1"
Nginx runs with www-data permissions. The permissions of the folder that the error message is referencing (/run/php/php5.6-fpm.sock) are as follows:
drwxr-xr-x 20 root root 700 Jun 28 09:45 run
drwxr-xr-x 2 www-data www-data 80 Jun 28 09:44 php
srw-rw---- 1 www-data www-data 0 Jun 28 09:44 php5.6-fpm.sock
The user/group of PHP (/etc/php/5.6/fpm/pool.d/www.conf) is:
user = www-data
group = www-data
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
The nginx.conf file does not have any user value set. Some people have suggested setting this to www-data, but if I set this the Nginx service won't start, hence why it is ommitted.
I fixed this by adding the following user directive to the top of my nginx.conf file:
user www-data www-data;

nginx: Can't connect to php-fpm socket

I'm seeing the following error in my nginx logs on my Ubuntu machine:
[crit] 14697#0: *1 connect() to unix:/home/php/run/php-fpm.sock failed (13: Permission denied) while connecting to upstream, client: x.y.z.w, server: mydomain.org, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/home/php/run/php-fpm.sock:", host: "mydomain.org"
Here are the permissions on the socket:
$ ll /home/php/run
total 8.0K
drwxr-xr-x 2 php php 4.0K Jan 10 18:56 .
drwxr-xr-x 12 php php 4.0K Jan 9 17:33 ..
srw-rw---- 1 php php 0 Jan 10 18:56 php-fpm.sock
The "nginx" process is run as the nginx user:
$ ps aux | grep nginx | grep -v grep
root 14694 0.0 0.3 88732 1784 ? Ss 19:08 0:00 nginx: master process /home/nginx/sbin/nginx -c /home/nginx/conf/nginx.conf
nginx 14697 0.0 1.0 88732 5112 ? S 19:08 0:00 nginx: worker process
I added the nginx user to the "php" group:
$ groups nginx
nginx : php
I tried restarting both nginx and php-fpm after doing so but I got the same failure. I am confused because the socket has permissions of 660, which should give read and write permissions to members of the php group. I'm also confused because the file appears writeable; if I run su - nginx and then run
$ test -w /home/php/run/php-fpm.sock ; echo $?
0
which seems to indicate that the nginx user can write to the socket. Why can't nginx write to the socket? What other information do I need to solve this problem?

Categories