Re: Custom configuration

55 views
Skip to first unread message

Adnan RIHAN

unread,
Mar 28, 2012, 12:09:50 PM3/28/12
to ng...@nginx.org
Sorry but, did I paste enough config files ?

Is there an error ? :/
---
Regards, Adnan RIHAN.
Président-Fondateur de l'association (de loi 1901) Virtual-Info, hébergeur Web et Serveurs de Jeux.
Consultant-Technicien Supérieur en Informatique de Gestion.
Ambassadeur Qt (Projet Tag-PG).

Le mercredi 28 mars 2012 à 09:48, Adnan RIHAN a écrit :

I'm actually using NGinx as webserver, for a hosting service, with CPanel. CPNginx, the name of the module.

root@shadow [/etc/cpnginx]# ls
./                data.conf           localkey.txt         uninstall.sh
../               direct/             md5.txt              version.txt
cpanelproxy.conf  expires/            nginx.cont.template  vhost.conf
custom/           fileextensions.txt  php.ini
root@shadow [/etc/cpnginx]# cat cpanelproxy.conf 
###### Security ########
server_tokens  off; 

###### To redirect cpanel.yourdomain.com ###########################3

server {
access_log off;
error_log  logs/vhost-error_log warn;
listen    80;
server_name  cpanel.* www.cpanel.*;
location / {
        client_max_body_size    10m;
        client_body_buffer_size 128k;
        proxy_send_timeout   90;
        proxy_read_timeout   90;
        proxy_buffer_size    4k;
        proxy_buffers     16 32k;
        proxy_busy_buffers_size 64k;
        proxy_temp_file_write_size 64k;
        proxy_connect_timeout 30s;
        proxy_redirect  http://www.cpanel.*:8888   http://www.cpanel.*;
        proxy_redirect  http://cpanel.*:8888   http://cpanel.*;
        proxy_pass   http://127.0.0.1:2082/;
        proxy_set_header   Host   $host;
        proxy_set_header   X-Real-IP  $remote_addr;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        }

}
################# To redirect whm.yourdomain.com #####################
server {
access_log off;
error_log  logs/vhost-error_log warn;
listen    80;
server_name  whm.* www.whm.*;
location / {
        client_max_body_size    10m;
        client_body_buffer_size 128k;
        proxy_send_timeout   90;
        proxy_read_timeout   90;
        proxy_buffer_size    4k;
        proxy_buffers     16 32k;
        proxy_busy_buffers_size 64k;
        proxy_temp_file_write_size 64k;
        proxy_connect_timeout 30s;
        proxy_redirect  http://www.whm.*:8888   http://www.whm.*;
        proxy_redirect  http://whm.*:8888   http://whm.*;
        proxy_pass   http://127.0.0.1:2086/;
        proxy_set_header   Host   $host;
        proxy_set_header   X-Real-IP  $remote_addr;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        }

}
######### To redirect  webmail.yourdomain.com ##################
server {
access_log off;
error_log  logs/vhost-error_log warn;
listen    80;
server_name  webmail.* www.webmail.*;
location / {
        client_max_body_size    10m;
        client_body_buffer_size 128k;
        proxy_send_timeout   90;
        proxy_read_timeout   90;
        proxy_buffer_size    4k;
        proxy_buffers     16 32k;
        proxy_busy_buffers_size 64k;
        proxy_temp_file_write_size 64k;
        proxy_connect_timeout 30s;
        proxy_redirect  http://www.webmail.*:8888   http://www.webmail.*;
        proxy_redirect  http://webmail.*:8888   http://webmail.*;
        proxy_pass   http://127.0.0.1:2095/;
        proxy_set_header   Host   $host;
        proxy_set_header   X-Real-IP  $remote_addr;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        }

}
############# To redirect webdisk.yourdomain.com ##################
server {
access_log off;
error_log  logs/vhost-error_log warn;
listen    80;
server_name  webdisk.* www.webdisk.*;
location / {
        client_max_body_size    10m;
        client_body_buffer_size 128k;
        proxy_send_timeout   90;
        proxy_read_timeout   90;
        proxy_buffer_size    4k;
        proxy_buffers     16 32k;
        proxy_busy_buffers_size 64k;
        proxy_temp_file_write_size 64k;
        proxy_connect_timeout 30s;
        proxy_redirect  http://www.webdisk.*:8888   http://www.webdisk.*;
        proxy_redirect  http://webdisk.*:8888   http://webdisk.*;
        proxy_pass   http://127.0.0.1:2077/;
        proxy_set_header   Host   $host;
        proxy_set_header   X-Real-IP  $remote_addr;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        }

}
################### WHM report #################################################
server {
error_log  logs/vhost-error_log warn;
listen    80;
location /whm-server-status {
                access_log /usr/local/apache/logs/access_log;
                proxy_pass http://127.0.0.1:8888/whm-server-status;
                proxy_set_header   Host   $host;
                proxy_set_header   X-Real-IP  $remote_addr;
                proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
}
root@shadow [/etc/cpnginx]# cat nginx.cont.template 
# cPanel Nginx Master configuration
user  nobody;
error_log  logs/error.log;
#Number of worker you need
worker_processes  1;
# How many connections a worker can handle maximum.
events {
    worker_connections  50000;
}
http {
include    mime.types;
  default_type  application/octet-stream;
  sendfile on;
server_names_hash_max_size 10000;
        server_names_hash_bucket_size 1024;
  tcp_nopush on;
  tcp_nodelay on;
  keepalive_timeout  10;
  gzip on;
  gzip_min_length  1100;
  gzip_buffers  4 32k;
  gzip_types    text/plain  application/x-javascript text/xml text/css;
  ignore_invalid_headers on;
  client_header_timeout  3m;
  client_body_timeout 3m;
  send_timeout     3m;
  include "/usr/local/nginx/conf/vhost.conf";
  include "/etc/cpnginx/cpanelproxy.conf";
}
And finally
root@shadow [/etc/cpnginx]# cat vhost.conf 
client_max_body_size    2000m;
client_body_buffer_size 512k;
proxy_send_timeout   90;
proxy_read_timeout   90;
proxy_buffer_size    32k;
proxy_buffers     16 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_connect_timeout 30s;
In custom, there is only one file, containing the previous posted config.

Thanks for your help. 
---
Ragards, Adnan RIHAN.
Président-Fondateur de l'association (de loi 1901) Virtual-Info, hébergeur Web et Serveurs de Jeux.
Consultant-Technicien Supérieur en Informatique de Gestion.
Ambassadeur Qt (Projet Tag-PG).

Le mercredi 28 mars 2012 à 08:02, Cliff Wells a écrit :

On Wed, 2012-03-28 at 07:16 +0200, Adnan RIHAN wrote:
I've done this:

root@shadow [/etc/cpnginx/custom]# cat mega-sound.be
location ~* \.mp3$ {
types {
application/octet-stream mp3;
}
}

But, after rebuilding vhost and restarted nginx, the mp3 are currently
audio/mpeg (referring to firefox).
Is there a way to check if the config is correctly "set" ?

Start by posting more of your configuration.

Cliff



_______________________________________________
nginx mailing list


Cliff Wells

unread,
Mar 28, 2012, 1:14:26 PM3/28/12
to ng...@nginx.org
On Wed, 2012-03-28 at 09:48 +0200, Adnan RIHAN wrote:

Which vhost is the one in question? Can you paste *only* the relevant
server block? Most of what you pasted appears to be specific to running
cPanel (I don't have any cPanel installs to check).

Also, you mention stuff in "custom", but I don't see where any of the
config you pasted includes a "custom" config.

locojohn

unread,
Mar 28, 2012, 2:31:19 PM3/28/12
to ng...@nginx.org
Adnan,

For the following to work you need headers module installed:

location ~ /(?<filename>(?!/).+\.mp3)$ {
types {
application/octet-stream mp3;
}
add_header Content-Disposition "attachment;
filename=\"$filename\"";
}

Kind regards,

Andrejs

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,224499,224577#msg-224577

Adnan RIHAN

unread,
Mar 28, 2012, 6:50:44 PM3/28/12
to ng...@nginx.org
Which vhost is the one in question? Can you paste *only* the relevant
server block? 
@Cliff: I didn't find them :/ I've asked the CPanel module devs to tell me where are the vhosts. Actually, I think nginx is just a "proxy" to apache, but it's strange... It means apache is still running and .htaccess working... I'll tell you as soon as I have the response.

Also, you mention stuff in "custom", but I don't see where any of the
config you pasted includes a "custom" config.
My custom conf is in "/custom/". This is what I had before @locojohn tip.
root@shadow [/etc/cpnginx/custom]# cat mega-sound.be 
location ~* \.mp3$ {
types {
application/octet-stream mp3;
}
}
 
 
For the following to work you need headers module installed:
Sorry but, what do you mean? Isn't "headers" a standard module ? How to check the compiled modules please ?

location ~ /(?<filename>(?!/).+\.mp3)$ {
types {
application/octet-stream mp3;
}
add_header Content-Disposition "attachment; filename=\"$filename\"";
}
This is my new custom config file. Nothing changed. Still audio/mpeg :/ 
---
Cordialement, Adnan RIHAN.

Président-Fondateur de l'association (de loi 1901) Virtual-Info, hébergeur Web et Serveurs de Jeux.
Consultant-Technicien Supérieur en Informatique de Gestion.
Ambassadeur Qt (Projet Tag-PG).

locojohn

unread,
Mar 28, 2012, 6:57:34 PM3/28/12
to ng...@nginx.org
> Sorry but, what do you mean? Isn't "headers" a standard module ? How
to check the compiled modules please ?

nginx -V

Try my solution, it works for me.

Andrejs

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,224499,224582#msg-224582

Adnan RIHAN

unread,
Mar 28, 2012, 7:07:36 PM3/28/12
to ng...@nginx.org
@Cliff: Here is the customer's vhost:
root@shadow [/etc/cpnginx/custom]# cat /usr/local/nginx/conf/vhost.conf | grep domain.com
########### Vhost configuration of  mega-sound.be
server_name  domain.com www.domain.com;
access_log /usr/local/apache/domlogs/domain.com;
        proxy_redirect  http://www.domain.com:8888   http://www.mega-sound.be;
        proxy_redirect  http://domain.com:8888   http://domain.com;
        proxy_redirect  http://domain.com:8888   http://domain.com;
include "/etc/cpnginx/custom/domain.com";

@locojohn: Here is the custom file:
root@shadow [/etc/cpnginx/custom]# cat domain.com 
location ~ /(?<filename>(?!/).+\.mp3)$ {
types {
application/octet-stream mp3;
}
add_header Content-Disposition "attachment; filename=\"$filename\"";
}

@locojohn: I'm using your custom config :/ . Plus, here is my nginx -V:
root@shadow [/etc/cpnginx/custom]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.0.11
built by gcc 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC) 
configure arguments: --prefix=/usr/local/nginx --with-openssl=/usr/

When I access a .mp3, here is the answer:
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 28 Mar 2012 23:06:25 GMT
Content-Type: audio/mpeg
Content-Length: 8976405
Last-Modified: Mon, 26 Mar 2012 18:50:14 GMT
Connection: keep-alive
Expires: Thu, 29 Mar 2012 23:06:25 GMT
Cache-Control: max-age=86400
Accept-Ranges: bytes
 
Thank you for your help.
---
Cordialement, Adnan RIHAN.
Président-Fondateur de l'association (de loi 1901) Virtual-Info, hébergeur Web et Serveurs de Jeux.
Consultant-Technicien Supérieur en Informatique de Gestion.
Ambassadeur Qt (Projet Tag-PG).

locojohn

unread,
Mar 28, 2012, 7:15:26 PM3/28/12
to ng...@nginx.org
Adnan, if it doesn't set the "Content-Disposition" header as per my
example, then it doesn't match the location in which this header is set.
It is likely that some other location has preference and so the code I
provided will never be triggered. Look into your nginx config more
closely. Also, check the error log, do you get any warnings?
Sometimes, PCRE library may throw a warning, maybe you can use
alternative location syntax compatible with an older version of PCRE:

...
location ~ /(?P<filename>(?!/).+\.mp3)$ {
...

Are your mp3 links static at all?

Andrejs

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,224499,224584#msg-224584

Adnan RIHAN

unread,
Mar 28, 2012, 7:21:40 PM3/28/12
to ng...@nginx.org
Unfortunately, it doesn't work.

Actually, the first thing i've tried, is:
types {
application/octet-stream mp3;
}
The only failure, is that with that, even CSS are downloaded (so, webste screwed up), and now I know that I HAVE to use "location".

I gave you an example link, the mp3 are in: /home/customer/www/adata/428.mp3, they're directly downloadable...

And poor me, the dev of CPNginx plugin told me that they don't support custom config, so they won't help me T_T

---
Cordialement, Adnan RIHAN.
Président-Fondateur de l'association (de loi 1901) Virtual-Info, hébergeur Web et Serveurs de Jeux.
Consultant-Technicien Supérieur en Informatique de Gestion.
Ambassadeur Qt (Projet Tag-PG).

Cliff Wells

unread,
Mar 28, 2012, 8:15:54 PM3/28/12
to ng...@nginx.org
On Wed, 2012-03-28 at 19:15 -0400, locojohn wrote:
> Adnan, if it doesn't set the "Content-Disposition" header as per my
> example, then it doesn't match the location in which this header is set.
> It is likely that some other location has preference and so the code I
> provided will never be triggered.

I'm fairly certain this is exactly what is happening. Either solution
should work fine, but only if the location is properly matched.

Again, it's not the preferred solution, but directly editing mime.types
would probably work.

Cliff

Adnan RIHAN

unread,
Mar 28, 2012, 8:36:21 PM3/28/12
to ng...@nginx.org
Mmmh...

Ok. I see, maybe there will never be any match, as there is only "proxy_redirect" in vhosts;
########### Vhost configuration of  mega-sound.be
access_log /usr/local/apache/domlogs/mega-sound.be;
        proxy_redirect  http://mega-sound.be:8888   http://mega-sound.be;
        proxy_redirect  http://mega-sound.be:8888   http://mega-sound.be;
include "/etc/cpnginx/custom/mega-sound.be";
Apache is still listening on :8888
Is there a chance with this conf, to match any "location" as there is no "document_root" or equivalent ?
I mean, location is system based or URL based?

If it's system, I don't know. If it's URL based, there should be a match since the first test.
Isn't it ?
---
Cordialement, Adnan RIHAN.
Président-Fondateur de l'association (de loi 1901) Virtual-Info, hébergeur Web et Serveurs de Jeux.
Consultant-Technicien Supérieur en Informatique de Gestion.
Ambassadeur Qt (Projet Tag-PG).

Adnan RIHAN

unread,
Mar 30, 2012, 1:08:37 AM3/30/12
to ng...@nginx.org
Hi,

Finally I need your help :/

The "CPNginx" devs have a website with a ticket support system, but they're telling me that they don't support custom configuration...
I've told them I need their help because they know how they built their module and how they made it work, they still just answer "You need to do it by yourself"...

What can I do T_T ?
---
Regards, Adnan RIHAN.

Président-Fondateur de l'association (de loi 1901) Virtual-Info, hébergeur Web et Serveurs de Jeux.
Consultant-Technicien Supérieur en Informatique de Gestion.
Ambassadeur Qt (Projet Tag-PG).

Adnan RIHAN

unread,
Mar 30, 2012, 3:11:11 AM3/30/12
to ng...@nginx.org
Hey everybody !

Here are some news.
I've compiled nginx with HttpHeadersMoreModule, to add custom headers in order to see if the location is or isn't matched.

Here is what I tried:
Custom config file:
root@shadow [/etc/cpnginx/custom]# cat mega-sound.be 
location ~* \.mp3$ {
        more_set_headers 'X-MyHeader: .mp3';
}

location /adata {
        more_set_headers 'X-MyHeader: adata';
}

more_set_headers 'X-MyMasterHeader: set';
The headers sent:
GET /adata/428.mp3 HTTP/1.1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:11.0) Gecko/20100101 Firefox/11.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cookie: cookie-data
If-Modified-Since: Mon, 26 Mar 2012 18:50:14 GMT
Cache-Control: max-age=0

And received 
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 30 Mar 2012 07:03:58 GMT
Content-Type: audio/mpeg
Content-Length: 8976405
Last-Modified: Mon, 26 Mar 2012 18:50:14 GMT
Connection: keep-alive
X-MyMasterHeader: set
Expires: Sat, 31 Mar 2012 07:03:58 GMT
Cache-Control: max-age=86400
Accept-Ranges: bytes
 
Do you have an idea :/ ?
Thank you for your help.
---
Cheers, Adnan RIHAN.

Président-Fondateur de l'association (de loi 1901) Virtual-Info, hébergeur Web et Serveurs de Jeux.
Consultant-Technicien Supérieur en Informatique de Gestion.
Ambassadeur Qt (Projet Tag-PG).

Adnan RIHAN

unread,
Mar 30, 2012, 11:45:05 AM3/30/12
to ng...@nginx.org
Ok.

Then, here is the vhost:
#################################################################
########### Vhost configuration of  mega-sound.be
#################################################################
server {
access_log off;
error_log  logs/vhost-error_log warn;
listen    80;
location ~* ^.+.(jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|iso|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|mp3|ogv|ogg|flv|swf|mpeg|mpg|mpeg4|mp4|avi|wmv|js|css)$ {
expires 24h;
root /home/megasoun/public_html;
error_page  404 = @apache;
access_log /usr/local/apache/domlogs/mega-sound.be;
log_not_found  off;
}
location ~ /\.ht {
          deny all;
}

location / {
log_not_found  off;

  client_max_body_size    2000m;
  client_body_buffer_size 512k;
  proxy_send_timeout   90;
  proxy_read_timeout   90;
  proxy_buffer_size    32k;
  proxy_buffers     16 32k;
  proxy_busy_buffers_size 64k;
  proxy_temp_file_write_size 64k;
  proxy_connect_timeout 30s;

        proxy_redirect  http://mega-sound.be:8888   http://mega-sound.be;
        proxy_pass   http://87.98.132.48:8888/;
        proxy_set_header   Host   $host;
        proxy_set_header   X-Real-IP  $remote_addr;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        }
location @apache {
internal;

  client_max_body_size    2000m;
  client_body_buffer_size 512k;
  proxy_send_timeout   90;
  proxy_read_timeout   90;
  proxy_buffer_size    32k;
  proxy_buffers     16 32k;
  proxy_busy_buffers_size 64k;
  proxy_temp_file_write_size 64k;
  proxy_connect_timeout 30s;

        proxy_redirect  http://mega-sound.be:8888   http://mega-sound.be;
        proxy_pass   http://87.98.132.48:8888;
        proxy_set_header   Host   $host;
        proxy_set_header   X-Real-IP  $remote_addr;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        }
include "/etc/cpnginx/custom/mega-sound.be";
}

Here is the included file:
root@shadow [/usr/local/nginx/conf]# cat /etc/cpnginx/custom/mega-sound.be
location ~* \.mp3$ {
        more_set_headers 'X-MyHeader: .mp3';
}

location /adata {
        more_set_headers 'X-MyHeader: adata';
}

more_set_headers 'X-MyMasterHeader: set';
more_set_headers 'X-My2Header: $request_uri';

Here is the HTTP Headers for the root URL (www.mega-sound.be):
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 30 Mar 2012 15:41:35 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
X-Powered-By: PHP/5.3.10
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: slrememberme=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT
X-MyMasterHeader: set
X-My2Header: /
Content-Encoding: gzip

Here is the headers for an MP3 (http://www.mega-sound.be/adata/362.mp3):
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 30 Mar 2012 15:43:04 GMT
Content-Type: audio/mpeg
Content-Length: 3258859
Last-Modified: Wed, 22 Feb 2012 13:52:13 GMT
Connection: keep-alive
X-MyMasterHeader: set
X-My2Heade: /adata/362.mp3
Expires: Sat, 31 Mar 2012 15:43:04 GMT
Cache-Control: max-age=86400
Accept-Ranges: bytes

Is it enough ?
Thank you for your help.
---
Cordialement, Adnan RIHAN.
Président-Fondateur de l'association (de loi 1901) Virtual-Info, hébergeur Web et Serveurs de Jeux.
Consultant-Technicien Supérieur en Informatique de Gestion.
Ambassadeur Qt (Projet Tag-PG).

Le vendredi 30 mars 2012 à 10:36, Francis Daly a écrit :

On Fri, Mar 30, 2012 at 07:08:37AM +0200, Adnan RIHAN wrote:

Hi there,

What can I do T_T ?


Look in your config file. Be aware of "include" directives. Look in
every server{} block. Look at "listen" and "server_name" directives in
each server{} block.

Identify which one server{} block is being used to handle this request.

Post the config for that server{}.

(If you can additionally identify which one location{} block within
that server{} block is being used for this request, then you could
limit what you post to: the server{} block outside of all location{}s,
plus the content of that one location{}. But that's probably more work
than is necessary.)


If you can enable the debug log (will probably require rebuilding
nginx), then you will see lots of information about what nginx thinks
is happening.

But posting the relevant part of the config file is the best way to make
it easy for people help you.

f
--
Francis Daly fra...@daoine.org

Adnan RIHAN

unread,
Mar 30, 2012, 7:35:52 PM3/30/12
to ng...@nginx.org

I knew that location are matched 1 time but I didn't noticed the |mp3 T_T

Thank you very much, I'm understanding more and more nginx.
I think it's done, I just have to deal with the CPanel NGinx module devs to change include place (in order to avoid this case another time).

Good night !
---
Cordialement, Adnan RIHAN.
Président-Fondateur de l'association (de loi 1901) Virtual-Info, hébergeur Web et Serveurs de Jeux.
Consultant-Technicien Supérieur en Informatique de Gestion.
Ambassadeur Qt (Projet Tag-PG).

Le vendredi 30 mars 2012 à 20:14, Francis Daly a écrit :

On Fri, Mar 30, 2012 at 05:45:05PM +0200, Adnan RIHAN wrote:

Hi there,

Then, here is the vhost:

Great, this shows why things are working the way they are.

location ~* ^.+.(jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|iso|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|mp3|ogv|ogg|flv|swf|mpeg|mpg|mpeg4|mp4|avi|wmv|js|css)$ {

This is the first regex location that matches mp3 urls, so this is the
one that will be used.

For what I think you want to do, you should remove "|mp3" from up there,
and then have the separate "~* \.mp3$" location later.

expires 24h;
root /home/megasoun/public_html;
error_page 404 = @apache;
access_log /usr/local/apache/domlogs/mega-sound.be;
log_not_found off;

Based on the rest of the config, you can probably move some of those to
"outside all locations", so that they will be inherited into all locations
that don't otherwise set them.

<snippage>
location / {
}

location @apache {
}

include "/etc/cpnginx/custom/mega-sound.be";
}

root@shadow [/usr/local/nginx/conf]# cat /etc/cpnginx/custom/mega-sound.be

As above, because this is included last in the main file, the mp3 location
here can never match.

So if you remove the "|mp3" up there, then this one will match:

location ~* \.mp3$ {
more_set_headers 'X-MyHeader: .mp3';

and now you can set your types, or do whatever else is needed, and have
it take effect.

(If your default or server-level "root" is not correct for this location,
you'll want to set that in here too.)

Because of the nginx location matching rules, this next location won't
be used for /adata/123.mp3, but will be used for /adata/123.html. You can
test that by putting a file of the right name in the right ("root"/adata)
directory, and seeing the X- header appearing.

location /adata {
more_set_headers 'X-MyHeader: adata';
}

And these two are outside of all locations, so apply to everything that
does not override them.

more_set_headers 'X-MyMasterHeader: set';
more_set_headers 'X-My2Header: $request_uri';

Here is the HTTP Headers for the root URL (www.mega-sound.be):

This is expected to be proxy_pass'ed to port 8888, and you can see that
your "all" more_set_headers directives did apply.

HTTP/1.1 200 OK
X-MyMasterHeader: set
X-My2Header: /

Here is the headers for an MP3 (http://www.mega-sound.be/adata/362.mp3):

This would match your original long location, so will be the file
/home/megasoun/public_html/adata/362.mp3 if it exists, and proxied to
port 8888 if it doesn't. Again, your "all" more_set_headers apply.

HTTP/1.1 200 OK
Content-Type: audio/mpeg
X-MyMasterHeader: set
X-My2Heade: /adata/362.mp3

If you remove "|mp3" from the first location; or just "include" this file
at the top instead of the bottom of the server{} block, then your custom
mp3 location would apply; and you should see your extra configuration
being used. (Without "root" set right, though, you may just end up with
a 404.)

http://www.nginx.org/r/location for the details on how nginx chooses
which one location{} block will be used for the current request, if
it's unclear.

All the best,
Capture d’écran 2012-03-31 à 01.34.16.png
Reply all
Reply to author
Forward
0 new messages