open() "directory/to/project" failed (13: Permission denied) nginx - php

I am using the default config with Nginx installed on my manjaro machine. I just added some simple configurations down below.
nginx.conf:
user http;
worker_processes auto;
worker_cpu_affinity auto;
.....
http{
.....
server {
listen 9000;
server_name localhost;
root /usr/share/nginx/html/exam;
location / {
index index.php index.html index.htm;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
if (!-e $request_filename){
rewrite ^/(.+)$ /index.php?url=$1 break;
}
}
location /. {
return 404;
}
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
include /etc/nginx/fastcgi.conf;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_intercept_errors on;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_read_timeout 864000;
}
location ~ /\.ht {
deny all;
}
}
....
}
since the user for Nginx is http, I also changed the ownership of the folder, subfolders and files as HTTP with:
chmod -R http:http exam/
it looks like this:
1838248 lrwxrwxrwx 1 http http 42 Eyl 13 17:42 exam
but still gives 403 Forbidden on browser with this error:
2021/09/13 17:49:22 [error] 493923#493923: *4 open() "/usr/share/nginx/html/exam/index.php" failed (13: Permission denied), client: 127.0.0.1, server: localhost, request: "GET /exam HTTP/1.1", host: "localhost:9000"
I have tried every solution I found, but it did not work.
I also tried simple PHP files that runs like "phpinfo();" even they are not working.

I moved the project file under /srv/http and redirect the root in the conf file to it. Now it is working.

Related

nginx error: openat() failed (20: not a directory) for images

I have a PHP project, a REST API. Nginx configuration is working for the API but is not for uploaded images
Images are always returning 404 error
the project starts at /public directory, upload directory is inside public, so the image access url is something like:
DOMAIN.COM/upload/201812/20181204133821.jpg
The actual NGINX configuration is
server {
listen 80;
listen [::]:80;
set $root_path '/usr/share/nginx/html/api/public';
root $root_path;
index index.php index.html index.htm;
server_name api-eduplus.blanco-estudio.com;
#try_files $uri $uri/ #rewrite;
try_files $uri $uri/ /index.php?q=$uri&$args;
location ~* \.(jpg|jpeg|png|gif)$ {
root $root_path;
expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
#error_log logs/error.log warn;
}
So the API starts at /public directory and images are uploaded into /public/upload/
Also. The nginx error log on the server says:
2018/12/04 16:35:54 [error] 17338: *1 openat() "/usr/share/nginx/html/api/public/upload/201812/20181204133821.jpg" failed (20: Not a directory), request: "GET /upload/201812/20181204133821.jpg HTTP/1.1"
Please help, I'm actually stuck
I just fixed this issue on my server. The cause of the error was a symlink.
I just encountered this (not very elucidating) error message on my server's nginx config:
"/path/to/index.html" is not found (20: Not a directory)
After some trial-and-error, I determined that the actual cause was that nginx couldn't access the site's document root because part of the path to the root included a symlink, but I had disable_symlinks on; set in my main nginx.conf file.
Commenting-out the disable_symlinks on; line or changing it to disable_symlinks off; fixes the issue.
See also:
https://nginx.org/en/docs/http/ngx_http_core_module.html#disable_symlinks

File Not Found when running Laravel with Nginx using LaraDock

I am learning Laravel using its tutorial. I installed Laravel and the required stacks using LaraDock.
Nginx returns File not found when I go to the IP where the app is running. Below is my NGINX configuration.
server {
root /var/www/laravel/public/;
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass php-upstream;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
This is the error from NGINX error log.
2016/08/19 08:53:06 [error] 47#47: *16 FastCGI sent in stderr:
"Primary script unknown" while reading response header from upstream,
client: 192.168.99.1, server: , request: "GET / HTTP/1.1", upstream:
"fastcgi://111.13.0.5:9000", host: "192.168.99.100"
To be sure you have index.php in /var/www/laravel/public/
run command
docker-compose exec nginx ls /var/www/laravel/public/
If you don't have index.php in the folder, probably your project folder mounted wrong.
Did you edit .env, or docker-compose.yml file?
Where you put laradock folder relative to your project folder

403 nginx error - permissions denied

I am getting 403 forbidden error when I try to access a domain using nginx. The nginx logs I get are:
[error] 13656#0: *4 "/var/www/example.com/www/index.php" is forbidden (13: Permission denied), client: 31.179.107.194, server: example.com, request: "GET / HTTP/1.1", host: "example.com"
/var/www/ has recursive 777 permissions. Sites-available config is:
#HTTP serve
#
server {
listen 80;
root /var/www/example.com/www/;
index index.php index.html index.htm;
server_name example.com;
access_log /var/log/nginx/example.com.access.log combined buffer=1024k;
error_log /var/log/nginx/example.com.error.log;
client_max_body_size 128M;
if (!-e $request_filename) {
rewrite ^/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/$ /index.php?controller=$1&action=$2 last;
}
location ~ \.php$ {
if (!-f $document_root/$fastcgi_script_name){
return 404;
}
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
proxy_connect_timeout 600s;
proxy_read_timeout 600s;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
nginx.conf contains user root; directive.
What's wrong?
One possible cause is that you are using SELinux. See Why does Nginx return a 403 even though all permissions are set properly?.
Also, setting user root is a security risk and is not recommended. Using an unprivileged user like 'www-data' or `nobody' is recommended, along with permissions that allow that user to access the minimal amount of data necessary.

nginx - phppgadmin - *1 access forbidden by rule

I want to setup phppgadmin, postgresql is already - done by following this article
but I have nginx,
I did so far these configs:
ln -s /usr/share/phppgadmin /var/www
and
/etc/nginx/sites-available/phppgadmin:
server{
listen 85;
server_name pgadmin.mypage.com;
root /var/www/phppgadmin;
index index.html index.html index.php;
access_log /var/log/phppgadmin/access.log;
error_log /var/log/phppgadmin/error.log;
location / {
allow my_page_IP;
deny all;
}
location ~ /\.ht {
deny all;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/phppgadmin$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}
and
ln -s /etc/nginx/sites-available/phppgadmin /etc/nginx/sites-enabled/
and
service nginx restart
but I am getting:
403 Forbidden
the error.log says:
2015/03/21 18:06:14 [error] 16916#0: *1 access forbidden by rule, client: 188.194.97.247, server: pgadmin.mypage.com, request: "GET / HTTP/1.1", host: "my_page_IP:85"
I did:
chmod -R 775 phppgadmin/
chown -R www-data:www-data phppgadmin/
but still the same 403 message. what am I doing wrong?
Access forbidden by rule mean that the access of the desired page was dropped by rule you have put in your configuration.
Just try to remove rule on each location to see which is cause problem.

create a block in nginx for symfony2

server {
listen 80;
server_name myapp.local
root /home/jack/Documents/projects/php/myapp/web;
location / {
#try_files $uri $uri/ /app_dev.php?$query_string;
#try_files $uri /app_dev.php$is_args$args;
try_files $uri #rewriteapp;
}
location #rewriteapp {
rewrite ^(.*)$ /app_dev.php/$1 last;
}
location ~ ^/(app|app_dev|config)\.php(/|$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
access_log /var/log/nginx/myapp-access.log;
error_log /var/log/nginx/myapp-error.log;
}
I've been trying to make this work but I couldn't and when I go to myapp.local I got No input file specified.. In the logs I have:
[error] 6867#0: *1 FastCGI sent in stderr: "Unable to open primary script: /usr/share/nginx/html/app.php (No such file or directory)" while reading response header from upstream, client: 127.0.0.1, server: myapp.local, request: "GET /app.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "myapp.local"
UPDATE
It looks like it's trying to access /usr/share/nginx/html/app.php, why in the world is it doing that?
nginx -v : 1.4.6
Believe it or not guys, after 4 hours of debugging I realized that it was all about a poor missing semicolon after server_name statement. What a shame!

Categories