简体   繁体   中英

Ngix 403 Forbidden - Ubuntu

My nginx keep throwing 403

I opened up the log, I see this

2019/10/23 12:08:25 [error] 28945#28945: *18 directory index of "/home/bheng/snake-river/public/" is forbidden, client: 20.231.19.250, server: default, request: "GET / HTTP/1.1", host: "167.99.234.85"

Then I went into my VM I ran this

chgrp www-data public/
service nginx reload

and now see this

drwxr-xr-x  5 root     www-data 4.0K Oct 23 12:15 public/

Refresh the page still the same ♂️

http://167.99.234.85/

ps -ef | grep nginx

root     29332     1  0 12:15 ?        00:00:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
root     29369 29164  0 12:16 pts/2    00:00:00 tail -f /var/log/nginx/default-error.log
www-data 29769 29332  0 12:40 ?        00:00:00 nginx: worker process
root     29771 29278  0 12:42 pts/3    00:00:00 grep nginx

sudo ufw app list

Available applications:
  Nginx Full
  Nginx HTTP
  Nginx HTTPS
  OpenSSH

I also tried $uri and $uri/

location / {
    try_files $uri $uri /index.php?$query_string;
    add_header 'Access-Control-Allow-Origin' '*';
}

and

location / {
    try_files $uri $uri/ /index.php?$query_string;
    add_header 'Access-Control-Allow-Origin' '*';
}

Same result


nginx.conf

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

It's might the firewall who block.

sudo ufw status to check.

https://help.ubuntu.com/community/UFW .

Incorrect file permissions are another cause of the "403 Forbidden" error. The standard setting of 755 for directories and 644 for files is recommended for use with NGINX. The NGINX user also needs to be the owner of the files.

Identify the NGINX User

To begin, you will need to determine what user NGINX is running as. To do this, use the command:

ps -ef | grep nginx

Check the first column, for any of the NGINX worker processes:

In this example, the NGINX worker process is running as the user nginx.

Set File Ownership

Go to the directory above the website's document root. For example, if your website's document root is /usr/share/nginx/example.com go to /usr/share/nginx with the command:

cd /usr/share/nginx

Change the ownership of all the files from this point down to the nginx user with the command:

sudo chown -R nginx:nginx

Set Permissions

Set the permissions of each directory at this location to 755 with the command:

sudo chmod 755 [directory name]

For example, to set the permissions of the example.com directory, the command is:

sudo chmod 755 example.com

Then go to the web document root directory:

cd example.com

Change the permissions of all the files in this directory with the command:

sudo chmod 644 *

https://www.ionos.com/community/server-cloud-infrastructure/nginx/solve-an-nginx-403-forbidden-error/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM