Question

Random 500 error with Nginx reverse proxy Apache without error log

Posted January 29, 2020 263 views
NginxApache

Hello all

I am getting some weird problem on my Nginx reverse proxy apache settings.

There is a random 500 error status code but nothing in the error log files (I can say it a about 20% of the traffic) as the site receives some thousand visits daily.

This is my Nginx config file

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

    events {
            worker_connections 4096; ## max clients = worker_processes * worker_connections
            multi_accept       on;
            use                epoll;
    }

    http {
            ##
            # Basic Settings
            ##
            sendfile on;
            tcp_nopush on;
            tcp_nodelay on;
            keepalive_timeout 65;
            client_body_timeout 12;
            client_header_timeout 12;
            send_timeout 10;
            types_hash_max_size 2048;
            server_tokens off;

            proxy_buffering on;
            proxy_buffer_size 16k;
            proxy_buffers 64 4k;
            proxy_busy_buffers_size 24k;

            include /etc/nginx/mime.types;
            default_type application/octet-stream;
            ## more tuning
            client_max_body_size 30M;
            client_body_buffer_size 12K;
            server_names_hash_max_size 1024;
            server_names_hash_bucket_size 112;

            client_header_buffer_size 2k;
            large_client_header_buffers 6 8k;

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

            ##
            # Logging Settings
            ##
            #access_log     off;
            log_not_found  off;
            access_log /var/log/nginx/access.log;
            error_log /var/log/nginx/error.log;
            ##
            # Gzip Settings
            ##
            gzip  on;
            gzip_vary on;
            gzip_min_length 1000;
            gzip_comp_level 9;
            gzip_proxied expired no-cache no-store private auth;
            gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
            gzip_disable "MSIE [1-6]\.";

            ##
            # Virtual Host Configs
            ##
            include /etc/nginx/conf.d/*.conf;
            include /etc/nginx/sites-enabled/*;
    }

And this is an example of a site config file.

        ## Static cache settings #
    proxy_cache_path /tmp/site.com levels=1:2 keys_zone=temgo_cache_zone-site.com:15m max_size=10g inactive=60m use_temp_path=off;

    server {
        listen 80;
        root /var/www/site.com;
        index index.php index.html index.htm;

        server_name site.com www.site.com;

        location ~ ^(.*)\.(inc|inc\.php|sql|ht|htaccess)$ {
            deny all;
        }
        location / {
            try_files $uri $uri/ =404;
        }

        ## Include full Mod rewrite rules
        include /etc/nginx/ssl/site_global_rewrite.conf;

        set $no_cache 0;
        if ($request_uri ~* "(/login.php|/register.php|/user.php)"){
            set $no_cache 1;
        }
        location ~ \.php$ {

              proxy_cache temgo_cache_zone-site.com;
              proxy_cache_key "$scheme$request_method$host$request_uri$is_Mobile_Browser$cookie_DeviceType$cookie__gallery"; ## Based on Mobile Device
              proxy_cache_bypass $no_cache;
              proxy_cache_revalidate on;
              proxy_cache_min_uses 1;
              proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
              proxy_cache_background_update on;
              proxy_cache_lock on;
              add_header Strict-Transport-Security "max-age=47474747; includeSubDomains; preload";
              add_header Content-Security-Policy upgrade-insecure-requests;
              add_header X-Frame-Options sameorigin always;
              add_header X-Cache-Status $upstream_cache_status;

              proxy_pass http://127.0.0.1:8080;
              include /etc/nginx/proxy_params;
        }

        listen 443 ssl http2; 
        ssl_certificate /etc/nginx/ssl/site.com.crt;
        ssl_certificate_key /etc/nginx/ssl/site.com.key;
    }

Can someone please advise what can be wrong?

Regards,
Jacques 

edited by KDSys

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.

×
2 answers

Hi @guiffo,

Looking at your Configuration files, I can’t seem to find a part in the Apache one where you’ve configured error_logs. Can you add this and see what the error is when the 500 Error is generated?

Additionally, is it a 500 Internal Server Error or is it 500 Http error? The difference is the first one is server related and the second one application related.

In such case, what I’ll recommend is trying to find a way to recreate the issue and act upon it then.

Regards,
KDSys

  • Hello

    Here is one example of my apache configured site

    <VirtualHost 127.0.0.1:8080>
        ServerAdmin webmaster@site.com
            ServerName site.com
            ServerAlias www.site.com    
        DocumentRoot /var/www/site.com
    
        ErrorDocument 404 /index.php?view=post404&errorcode=404
        ErrorDocument 400 /index.php?view=post404&errorcode=400
        ErrorDocument 401 /index.php?view=post404&errorcode=401
        ErrorDocument 403 /index.php?view=post404&errorcode=403
        ErrorDocument 500 /index.php?view=post404&errorcode=500
            ErrorDocument 501 /index.php?view=post404&errorcode=501
            ErrorDocument 502 /index.php?view=post404&errorcode=502
            ErrorDocument 503 /index.php?view=post404&errorcode=503
            ErrorDocument 504 /index.php?view=post404&errorcode=504
    
            <Directory /var/www/>
           Options Indexes FollowSymLinks MultiViews
           AllowOverride All
           Order allow,deny
           allow from all
        </Directory>
    </VirtualHost>
    
  • At the moment I can catch some of the 500 erros based on apache conf ErrorDocument 500 /index.php?view=post404&errorcode=500 (where I have configured some PHP script to inform me about the 500 error but of course nothing on the server sites errors logs) but there is nothing in the /var/log/apache/error.log nor /var/log/nginx/error.log

    • Hi @guiffo,

      Try adding this to your Vhost file for your website

      <VirtualHost *:80>
          Some Code here
          ErrorLog ${APACHE_LOG_DIR}/error.log
          CustomLog ${APACHE_LOG_DIR}/access.log combined
      
      </VirtualHost>
      

      It will allow your server to post error and access logs to the Apache’s main error and access logs rather than a separate or non at all log.

      The other issue might be, lack of resources which causes your server to kill the processes for the website resulting in a 500 internal error.

      Regards,
      KDSys

Hello

I have done so but there is no error at all.

But having a very closed look, I notice that the 500 error are through when Nginx send 103 status code to apache (honestly not sure why)

site.com:443 127.0.0.1 - - [08/Feb/2020:15:54:47 +0000] “GET /index.php HTTP/1.1” 103 32998 “-” “curl/7.64.1”

Can someone have glue? Is there a way to disable 103 status code?

Submit an Answer