Author Topic: Nginx force download and custom error pages  (Read 12608 times)

0 Members and 1 Guest are viewing this topic.

Offline
*
Nginx force download and custom error pages
« on: September 23, 2019, 07:26:19 PM »
Hello,

I have a couple of VPS with CWP installed and all of them are configured to use Nginx & Apache as WebServer. I recently had to rebuild the WebServer of one VPS as CWP was forcing me to do but since then Nginx force download for specific extensions aren't working as well as custom error pages. I have checked the Nginx version of the server where these two are not working and its' nginx/1.16.1. But they are working fine on CWP installation with nginx/1.14.0. I used the following configuration on nginx vhosts -


Quote
location ~* (.*\.mp4) {
types { application/octet-stream .mp4; }
default_type application/octet-stream;
}


error_page 404 403 /404.shtml;
        location = /404.shtml {
        root /path/to/directory;
                internal;
        }


Above configuration is working fine on nginx/1.14.0 but doesn't seem to be working on nginx/1.16.1.

Quote
[root@server1 ~]# nginx -v
nginx version: nginx/1.16.1
[root@server1 ~]# grep version /usr/local/cwpsrv/htdocs/resources/admin/include/version.php| awk '{print $NF}'| tr -d '"|;'
0.9.8.697
[root@server1 ~]#

Can anyone please assist me to configure Nginx force download and custom error pages on nginx/1.16.1 ?

Offline
*
Re: Nginx force download and custom error pages
« Reply #1 on: September 27, 2019, 04:48:19 PM »
Anyone?

Offline
*
Re: Nginx force download and custom error pages
« Reply #2 on: May 03, 2020, 06:46:15 AM »
Hi,

I'm still looking for a solution to this.

Offline
****
Re: Nginx force download and custom error pages
« Reply #3 on: May 03, 2020, 08:36:24 AM »
Post the entire config file, not just a snippet.  Are these in a location block,  Server block,  http block?  Chances are another block is taking prescience.
Google Hangouts:  rcschaff82@gmail.com

Offline
*
Re: Nginx force download and custom error pages
« Reply #4 on: May 03, 2020, 10:57:56 AM »
Hi,

Thanks for the reply.

Please find the nginx.conf as follows

Code: [Select]
user nobody;
worker_processes auto;
#worker_rlimit_nofile    65535;
error_log               /var/log/nginx/error.log crit;
pid                     /var/run/nginx.pid;

events {
worker_connections  1024;
use                 epoll;
multi_accept        on;

}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
client_header_timeout 3m;
client_body_timeout 3m;
client_max_body_size 256m;
client_header_buffer_size 4k;
client_body_buffer_size 256k;
large_client_header_buffers 4 32k;
send_timeout 3m;
keepalive_timeout 60 60;
reset_timedout_connection       on;
server_names_hash_max_size 1024;
server_names_hash_bucket_size 1024;
ignore_invalid_headers on;
connection_pool_size 256;
request_pool_size 4k;
output_buffers 4 32k;
postpone_output 1460;

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

# Compression gzip
gzip on;
gzip_vary on;
gzip_disable "MSIE [1-6]\.";
gzip_proxied any;
gzip_min_length 512;
gzip_comp_level 6;
gzip_buffers 8 64k;
gzip_types text/plain text/xml text/css text/js application/x-javascript application/xml image/png image/x-icon image/gif image/jpeg image/svg+xml application/xml+rss text/javascript application/atom+xml application/javascript application/json application/x-font-ttf font/opentype;

# Proxy settings
proxy_redirect      off;
proxy_set_header    Host            $host;
proxy_set_header    X-Real-IP       $remote_addr;
proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass_header   Set-Cookie;
proxy_connect_timeout   300;
proxy_send_timeout  300;
proxy_read_timeout  300;
proxy_buffers       32 4k;
proxy_cache_path /var/cache/nginx levels=2 keys_zone=cache:10m inactive=60m max_size=512m;
proxy_cache_key "$host$request_uri $cookie_user";
proxy_temp_path  /var/cache/nginx/temp;
proxy_ignore_headers Expires Cache-Control;
proxy_cache_use_stale error timeout invalid_header http_502;
proxy_cache_valid any 1d;
proxy_intercept_errors on;

open_file_cache_valid 120s;
open_file_cache_min_uses 2;
open_file_cache_errors off;
open_file_cache max=5000 inactive=30s;
open_log_file_cache max=1024 inactive=30s min_uses=2;

# SSL Settings
ssl_session_cache   shared:SSL:10m;
ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers        "EECDH+ECDSA+AESGCM:EECDH+aRSA+AESGCM:EECDH+ECDSA+SHA384:EECDH+ECDSA+SHA256:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EECDH+aRSA!RC4:EECDH:!RC4:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS";

# Logs
log_format  main    '$remote_addr - $remote_user [$time_local] $request '
                '"$status" $body_bytes_sent "$http_referer" '
                '"$http_user_agent" "$http_x_forwarded_for"';
log_format  bytes   '$body_bytes_sent';
#access_log          /var/log/nginx/access.log main;
access_log off;

# Cache bypass
map $http_cookie $no_cache {
default 0;
~SESS 1;
~wordpress_logged_in 1;
}

# Include additional configuration
include /etc/nginx/cloudflare.inc;
include /etc/nginx/conf.d/*.conf;
}

And here's vhost configuration file -

Code: [Select]
server {
listen 111.222.333.44:80;
server_name subdomain.domain.com  www.subdomain.domain.com;

access_log /usr/local/apache/domlogs/subdomain.domain.com.bytes bytes;
access_log /usr/local/apache/domlogs/subdomain.domain.com.log combined;
error_log /usr/local/apache/domlogs/subdomain.domain.com.error.log error;

location / {
location ~.*\.(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|html|htm|txt|js|css|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso|woff|ttf|svg|eot|sh)$ {
root /home/path/to/the/documnet/root;
expires max;
try_files $uri @backend;
}

error_page 404 403 /404.shtml;
        location = /404.shtml {
        root /home/path/to/the/documnet/root;
                internal;
        }


error_page 405 = @backend;
error_page 500 = @custom;
add_header X-Cache "HIT from Backend";
proxy_pass http://111.222.333.444:8181;
include proxy.inc;
}

location ~* (.*\.mp3) {
types { application/octet-stream .mp3; }
default_type application/octet-stream;
}


location @backend {
internal;
proxy_pass http://111.222.333.444:8181;
include proxy.inc;
}

location @custom {
internal;
proxy_pass http://111.222.333.444:8181;
include proxy.inc;
}

location ~ .*\.(php|jsp|cgi|pl|py)?$ {
proxy_pass http://111.222.333.444:8181;
include proxy.inc;
}

location ~ /\.ht    {deny all;}
location ~ /\.svn/  {deny all;}
location ~ /\.git/  {deny all;}
location ~ /\.hg/   {deny all;}
location ~ /\.bzr/  {deny all;}

disable_symlinks if_not_owner from=/home/path/to/the/documnet/root;

location /.well-known/acme-challenge {
default_type "text/plain";
alias /usr/local/apache/autossl_tmp/.well-known/acme-challenge;
}
}


I have added rules for custom 404 error page and force download in the vhost file. The exact same configuration was working fine before getting nginx updated.

Offline
****
Re: Nginx force download and custom error pages
« Reply #5 on: May 03, 2020, 05:45:56 PM »
There were patches in 1.16.  .14 was not handling as they expected.

I believe your issue with downloads is.
location ~.*\.(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|html|htm|txt|js|css|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso|woff|ttf|svg|eot|sh)$ {
         root /home/path/to/the/documnet/root;               
         expires max;
         try_files $uri @backend;
}

Try putting your force downloads inside this block so it is reevaluated.
Google Hangouts:  rcschaff82@gmail.com

Offline
*
Re: Nginx force download and custom error pages
« Reply #6 on: May 03, 2020, 06:24:40 PM »
Force download is working perfectly now :) Thank you very much!
Can you please suggest something to get the custom error page working? I have already set proxy_intercept_errors on; to nginx.conf and set custom 404 error page on vhost file which used to work on older nginx versions.

Offline
****
Re: Nginx force download and custom error pages
« Reply #7 on: May 03, 2020, 06:33:17 PM »
Try moving them up the config.  Like immediately after the "location / { " and before the first location match block.  See what happens.

Nginx can be very touchy on where you can and can't put config options.
Google Hangouts:  rcschaff82@gmail.com

Offline
*
Re: Nginx force download and custom error pages
« Reply #8 on: January 12, 2021, 06:05:18 PM »
Hello,

I have a couple of VPS with CWP installed and all of them are configured to use Nginx & Apache as WebServer. I recently had to rebuild the WebServer of one VPS as CWP was forcing me to do but since then Nginx force download for specific extensions aren't working as well as custom error pages. I have checked the Nginx version of the server where these two are not working and its' nginx/1.16.1. But they are working fine on CWP installation with nginx/1.14.0. I used the following configuration on nginx vhosts -


Quote
location ~* (.*\.mp4) {
types { application/octet-stream .mp4; }
default_type application/octet-stream;
}

MyWMTotalRewards MyBPCreditCard


error_page 404 403 /404.shtml;
        location = /404.shtml {
        root /path/to/directory;
                internal;
        }


Above configuration is working fine on nginx/1.14.0 but doesn't seem to be working on nginx/1.16.1.

Quote
[root@server1 ~]# nginx -v
nginx version: nginx/1.16.1
[root@server1 ~]# grep version /usr/local/cwpsrv/htdocs/resources/admin/include/version.php| awk '{print $NF}'| tr -d '"|;'
0.9.8.697
[root@server1 ~]#

Can anyone please assist me to configure Nginx force download and custom error pages on nginx/1.16.1 ?

What happened ?Waiting for your answer.As i really want to know about it..I hope u will reply soon

Offline
*****
Re: Nginx force download and custom error pages
« Reply #9 on: February 17, 2021, 11:06:59 AM »
I see only one change about the issue in nginx changelog:

Code: [Select]
Bugfix: standard error pages and responses of the
       ngx_http_autoindex_module module used the "bgcolor" attribute, and
       might be displayed incorrectly when using custom color settings in
       browsers.

So, it does not look like an nginx problem.
You can ask me to solve any problem with your server for some money in pm  ;)
Services Monitoring & RBL Monitoring
http://centos-webpanel.com/services-monitor
Join our Development Team and get paid !
http://centos-webpanel.com/develope-modules-for-cwp

Installation Instructions
http://centos-webpanel.com/installation-instructions
Get Fast Support Here
http://centos-webpanel.com/support-services