403 error (Laravel + nginx + centos7) alibaba ecs - php

Trying to host my laravel website onto an Alibaba ECS framework through the use of nginx, however i keep encoutering the error 403 where the directory permission is forbidden.
I have tried
1) chmod o+x /usr/share/nginx/html/laravel
2) chown -R root:root /usr/share/nginx/html/laravel
3) chmod -R 777 /usr/share/nginx/html/laravel
All to no avail
Can someone please tell me what i am doing wrongly... thank you!
server {
listen 80;
server_name -IP ADDRESS-;
root /usr/share/nginx/html/laravel;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html/laravel;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Directory Permission path
[root#directory laravel]# namei -om /usr/share/nginx/html/laravel
f: /usr/share/nginx/html/laravel
drwxr-xr-x root root /
drwxr-xr-x root root usr
drwxr-xr-x nginx nginx share
drwxr-xr-x nginx nginx nginx
drwxr-xr-x nginx nginx html
drwxr-xr-x nginx nginx laravel
Error Message
2021/04/27 19:15:50 [error] 23810#0: *1 directory index of "/usr/share/nginx/html/laravel/" is forbidden, client: IP ADDRESS, server: IP ADDRESS, request: "GET / HTTP/1.1", host: "IP ADDRESS"

Related

Nginx error : "Primary script unknown ", how can I resolve that ? Thank you

Config :
macOS Mojave
Debian 9.9.0 64bits on virtualbox 6.0.8, on port 192.168.56.50
php fpm 7.2 on debian
nginx/stable,now 1.16.0-1~stretch on debian
Nginx and php fpm have www-data as user.
Dirs :
lrwxrwxrwx www-data www-data /var/www/all -> /media/sf_web
drwxrwx--- www-data www-data /var/www
Config nginx :
/etc/nginx/conf.d/default.conf
server {
listen 80;
server_name _;
charset utf-8;
location / {
root /var/www/all/;
try_files $uri /index.html index.php;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
When i do this command : sudo ls -l /var/www/all/ , i get :
drwxrwx--- 1 root vboxsf temp_converter
drwxrwx--- 1 root vboxsf myproject
I want to show projects folders under /media/sf_web using Firefox (or another web browser) but it doesn't work.
When i try to connect on this ip , nginx show "File not found" and in error log i see "Primary script unknow".
e.j :
http://192.168.56.50
http://192.168.56.50/myproject/index.php
You haven't set a global root statement, so Nginx will look for PHP files in the default root. You need to move the root statement from inside the location / block into server block scope.
The try_files statement is completely wrong.
Try:
root /var/www/all/;
location / {
try_files $uri $uri/ /index.php;
}
...
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $request_filename;
}

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

502 Bad Gateway with PHP7 and Nginx 1.9.9

I'm getting a 502 Bad Gateway error with PHP7 and nginx 1.9.9 installed on Ubuntu 14.04 when I try to access any .php files. .html files load as expected.
I've updated the default.conf to:
server {
listen 80 default_server;
root /usr/share/nginx/html;
index index.html index.htm index.php;
server_name localhost;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
I've updated php.ini with cgi.fix_pathinfo = 0 and then rebooted the server, and am still getting the 502 error with all .php files. I have checked to ensure php7.0-fpm.sock is installed and in the proper location.
This is the error I'm getting from the nginx log 2016/01/19 19:14:54 [error] 1466#1466: *1 open() "/usr/share/nginx/html/xmlrpc.php" failed (2: No such file or directory), client: 85.159.237.13, server: localhost, request: "POST /xmlrpc.php HTTP/1.0", host: "my.ip.address"
I've searched for the answer for quite a while and I'm out of ideas. Does anyone have any suggestions?
This is mostly because your nginx and php7.0-fpm were not run under the same user. Edit nginx.conf and change "user nginx" to "user www-data"
By the way, "client: 85.159.237.13", that was a script boy, I think.

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.

Nginx stat() failed (13: Permission Denied)

Okay so there have been some previous posting of this yet no solution fixes my problem.
I have site configured which is just straight up HTML, CSS & JS and I'm trying to add a wordpress site. My config for the wordpress site is as follows.
#######################
server {
listen 80;
root /usr/share/nginx/threadtheatre/wordpress;
index index.php;
server_name threadtheatre.co.uk;
access_log /var/log/nginx/thread.access.log;
error_log /var/log/nginx/thread.error.log;
location / {
# try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
This is the error thats in my logs
"/usr/share/nginx/threadtheatre/wordpress/index.php" failed (13: Permission denied), client: 109.155.53.189, server: threadtheatre.co.uk, request: "GET / HTTP/1.1", host: "threadtheatre.co.uk"
nginx is using the nginx user and likewise for php-fpm. The nginx directory and all its sub directories have the following permissions.
drwxrwxr-x. 3 root nginx 4096 Feb 8 18:23 ..
If I browse to threadtheatre.co.uk on the web i get 404.
hope someone can help with this.
Lee.
Do you still have this problem? This explanation worked for me:
https://serverfault.com/a/170263/140684
basically nginx needs to have execution rights on every dir on the path to your app. Hope this helps.
for me this is because selinux enabled, check with
selinuxenabled && echo enabled || echo disabled
if enabled try to disable
nano /etc/sysconfig/selinux
SELINUX=disabled
then
reboot
If nginx is hosted on Fedora or RedHat , change the SELinux policy and allow nginx to serve from the path /home/path/site
chcon -R -t httpd_sys_content_t /home/path/site

Categories