Question

403 Forbidden nginx ERROR SHOWING AFTER RESTART. PLEASE HELP

Posted April 26, 2017 61.6k views
NginxApacheUbuntu 16.04

Everything was working fine.. eventually i restarted the server to check something.. and now this error is showing all over the place. 138.197.92.156 domains also please help

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
3 answers

Hi @geeber05
Run this command to show the last errors in Nginx:

tail -20 /var/log/nginx/error.log

@geeber05
Can you post your Nginx server block configuration?
Also make sure you actually have files in that directory ls -l /var/www/html

server {
listen 80 defaultserver;
listen [::]:80 default
server;

# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
# include snippets/snakeoil.conf;
#
# ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # don’t use SSLv3 ref: POODLE
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;

root /var/www/html;

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;

server_name _;

location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to displaying a 404.
    try_files $uri $uri/ =404;
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
#   include snippets/fastcgi-php.conf;
#
#   # With php5-cgi alone:
#   fastcgi_pass 127.0.0.1:9000;
#   # With php5-fpm:
#   fastcgi_pass unix:/var/run/php5-fpm.sock;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#   deny all;
#}

}

Virtual Host configuration for example.com

You can move that to a different file under sites-available/ and symlink that

to sites-enabled/ to enable it.

server {

listen 80;

listen [::]:80;

server_name example.com;

root /var/www/example.com;

index index.html;

location / {

try_files $uri $uri/ =404;

}

  • @geeber05
    Is there only one file? That’s the default configuration, which doesn’t do much. You need to replace that with a configuration, which has php-fpm and some WordPress adjustments.

    Have a look in /etc/nginx/sites-available/ - do you also only have one configuration file?

    • I only have one file that is from etc/nginx/sites-available

      • @geeber05 Okay, then you’ve lost your configuration.
        Here’s an example configuration that will work for WordPress - restart Nginx after changes

        server {
            listen 80 default_server;
            listen [::]:80 default_server;
        
            root /var/www/html;
            index index.php index.html index.htm;
        
            server_name _;
        
            location / {
                try_files $uri $uri/ /index.php?$args;
            }
        
            location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
            }
        
            location ~ /\.ht {
                deny all;
            }
        }
        
    • You should look at the following URL’s in order to grasp a solid understanding

      of Nginx configuration files in order to fully unleash the power of Nginx.

      http://wiki.nginx.org/Pitfalls

      http://wiki.nginx.org/QuickStart

      http://wiki.nginx.org/Configuration

      Generally, you will want to move this file somewhere, and start with a clean

      file but keep this around for reference. Or just disable in sites-enabled.

      Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.

      Default server configuration

      server {
      listen 80 defaultserver;
      listen [::]:80 default
      server;

      # SSL configuration
      #
      # listen 443 ssl default_server;
      # listen [::]:443 ssl default_server;
      #
      # Self signed certs generated by the ssl-cert package
      # Don't use them in a production server!
      # include snippets/snakeoil.conf;
      #
      # ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # don’t use SSLv3 ref: POODLE
      # ssl_ciphers HIGH:!aNULL:!MD5;
      # ssl_prefer_server_ciphers on;
      
      root /var/www/html;
      
      # Add index.php to the list if you are using PHP
      index index.html index.htm index.nginx-debian.html;
      
      server_name _;
      
      location / {
          # First attempt to serve request as file, then
          # as directory, then fall back to displaying a 404.
          try_files $uri $uri/ =404;
      }
      
      # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
      #
      #location ~ \.php$ {
      #   include snippets/fastcgi-php.conf;
      #
      #   # With php5-cgi alone:
      #   fastcgi_pass 127.0.0.1:9000;
      #   # With php5-fpm:
      #   fastcgi_pass unix:/var/run/php5-fpm.sock;
      #}
      
      # deny access to .htaccess files, if Apache's document root
      # concurs with nginx's one
      #
      #location ~ /\.ht {
      #   deny all;
      #}
      

      }

      Virtual Host configuration for example.com

      You can move that to a different file under sites-available/ and symlink that

      to sites-enabled/ to enable it.

      server {

      listen 80;

      listen [::]:80;

      server_name example.com;

      root /var/www/example.com;

      index index.html;

      location / {

      try_files $uri $uri/ =404;

      }

Submit an Answer