403 Foridden

Discussion in 'Nginx' started by mdm100, May 23, 2018.

  1. #1
    403 Forbidden
    nginx/1.12.1 (Ubuntu)

    Distributor ID: Ubuntu
    Description: Ubuntu 17.10
    Release: 17.10
    Codename: artful

    I have many virtual sites running on my server identical to this one, but for some reason I have run into the 403 wall.

    Permissions for my virtual website dir
    sudo chown -R www-data:www-data /var/www/html/C1/
    sudo chmod -R 755 /var/www/html/C1/
    results
    drwxrwxrwx 3 www-data www-data 4096 May 23 12:37 C1
    Code (markup):
    The virtual directory is as follows.. and is linked to.
    sudo ln -s /etc/nginx/sites-available/c1 /etc/nginx/sites-enabled/
    
    server {
    listen 80;
    listen [::]:80;
    root /var/www/html/C1;
    index index.html index.php index.htm;
    server_name c1inventory.xxxxxxx.com;
    
    location / {
    try_files $uri $uri/ /index.php?$query_string;
    }
    
    
    location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_index index.php;
    fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
    include fastcgi_params;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
    
    }
    Code (markup):
    Dump from the nginx error log.

    2018/05/23 14:15:49 [error] 1530#1530: *1 directory index of "/var/www/html/C1/" is forbidden, client: 67.127.276.257, server: c1inventory.xxxxxx.com, request: "GET / HTTP/1.1", host: "c1inventory.xxxxxx.com"
    Code (markup):
    Any help is greatly appreciated.

    Thanks.
     
    mdm100, May 23, 2018 IP
  2. hostechsupport

    hostechsupport Well-Known Member

    Messages:
    413
    Likes Received:
    23
    Best Answers:
    7
    Trophy Points:
    138
    #2
    The 403 Forbidden error shows that the file has bad permissions. Directories and folders must be 755. Executable scripts within the cgi-bin folder must be 755. Images, media, and text files like HTML should be 755 or 644.

    You can try out the following command:
    sudo chown -R www-data:www-data /usr/share/nginx/html/*
    sudo chmod -R 0755 /usr/share/nginx/html/*
     
    hostechsupport, May 24, 2018 IP
  3. AlphaNine_Vini

    AlphaNine_Vini Active Member

    Messages:
    218
    Likes Received:
    10
    Best Answers:
    1
    Trophy Points:
    88
    #3
    -R is enough to change the permission of files and folder on the target folder.
     
    AlphaNine_Vini, Jun 8, 2018 IP
  4. AlphaNine_Vini

    AlphaNine_Vini Active Member

    Messages:
    218
    Likes Received:
    10
    Best Answers:
    1
    Trophy Points:
    88
    #4
    Check the permission of C1 folder specifically.
     
    AlphaNine_Vini, Jun 8, 2018 IP
  5. GoMummy-GM

    GoMummy-GM Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #5
    Are you using PHP-FPM with Nginx?
    If so then go to PHP-FPM
    www.conf
    Code (markup):
    file and edit the below two lines and save and exit the file and restart Nginx, PHP-FPM service both.

    #
    vim /etc/php-fpm.d/www.conf.
    Code (markup):
    .
    user = nginx
    .
    group = nginx

    create an info.php file in /usr/share/nginx/html file using below code. save the file and exit.

    <?php

    phpinfo();

    ?>

    now browse the file using your server IP
    http://xx.xx.xx.xx/info.php
    Code (markup):
    . it should work.
     
    GoMummy-GM, Feb 17, 2020 IP