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.txtcpanelproxy.conf expires/ nginx.cont.template vhost.confcustom/ fileextensions.txt php.iniroot@shadow [/etc/cpnginx]# cat cpanelproxy.conf###### Security ########server_tokens off;###### To redirect cpanel.yourdomain.com ###########################3server {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 configurationuser nobody;error_log logs/error.log;#Number of worker you needworker_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 finallyroot@shadow [/etc/cpnginx]# cat vhost.confclient_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.belocation ~* \.mp3$ {types {application/octet-stream mp3;}}But, after rebuilding vhost and restarted nginx, the mp3 are currentlyaudio/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
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.
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
Which vhost is the one in question? Can you paste *only* the relevantserver block?
Also, you mention stuff in "custom", but I don't see where any of theconfig you pasted includes a "custom" config.
root@shadow [/etc/cpnginx/custom]# cat mega-sound.belocation ~* \.mp3$ {types {application/octet-stream mp3;}}
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\"";}}
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
root@shadow [/etc/cpnginx/custom]# cat /usr/local/nginx/conf/vhost.conf | grep domain.com########### Vhost configuration of mega-sound.be
root@shadow [/etc/cpnginx/custom]# cat domain.com
location ~ /(?<filename>(?!/).+\.mp3)$ {types {application/octet-stream mp3;}add_header Content-Disposition "attachment; filename=\"$filename\"";}
root@shadow [/etc/cpnginx/custom]# /usr/local/nginx/sbin/nginx -Vnginx version: nginx/1.0.11built by gcc 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC)configure arguments: --prefix=/usr/local/nginx --with-openssl=/usr/
HTTP/1.1 200 OKServer: nginxDate: Wed, 28 Mar 2012 23:06:25 GMTContent-Type: audio/mpegContent-Length: 8976405Last-Modified: Mon, 26 Mar 2012 18:50:14 GMTConnection: keep-aliveExpires: Thu, 29 Mar 2012 23:06:25 GMTCache-Control: max-age=86400Accept-Ranges: bytes
...
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
types {application/octet-stream mp3;}
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
########### Vhost configuration of mega-sound.be
server_name mega-sound.be www.mega-sound.be;access_log /usr/local/apache/domlogs/mega-sound.be;proxy_redirect http://www.mega-sound.be:8888 http://www.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";
root@shadow [/etc/cpnginx/custom]# cat mega-sound.belocation ~* \.mp3$ {more_set_headers 'X-MyHeader: .mp3';}location /adata {more_set_headers 'X-MyHeader: adata';}more_set_headers 'X-MyMasterHeader: set';
GET /adata/428.mp3 HTTP/1.1Host: www.mega-sound.beUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:11.0) Gecko/20100101 Firefox/11.0Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3Accept-Encoding: gzip, deflateConnection: keep-aliveReferer: http://www.mega-sound.be/Cookie: cookie-dataIf-Modified-Since: Mon, 26 Mar 2012 18:50:14 GMTCache-Control: max-age=0
HTTP/1.1 200 OKServer: nginx
Date: Fri, 30 Mar 2012 07:03:58 GMT
Content-Type: audio/mpegContent-Length: 8976405Last-Modified: Mon, 26 Mar 2012 18:50:14 GMTConnection: keep-alive
X-MyMasterHeader: setExpires: Sat, 31 Mar 2012 07:03:58 GMTCache-Control: max-age=86400Accept-Ranges: bytes
#################################################################
########### Vhost configuration of mega-sound.be
#################################################################
server {access_log off;error_log logs/vhost-error_log warn;listen 80;
server_name mega-sound.be www.mega-sound.be;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://www.mega-sound.be:8888 http://www.mega-sound.be;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";}
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';
HTTP/1.1 200 OKServer: nginx
Date: Fri, 30 Mar 2012 15:41:35 GMTContent-Type: text/htmlTransfer-Encoding: chunkedConnection: keep-aliveX-Powered-By: PHP/5.3.10Expires: Thu, 19 Nov 1981 08:52:00 GMTCache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0Pragma: no-cacheSet-Cookie: slrememberme=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMTX-MyMasterHeader: setX-My2Header: /Content-Encoding: gzip
HTTP/1.1 200 OKServer: nginx
Date: Fri, 30 Mar 2012 15:43:04 GMTContent-Type: audio/mpegContent-Length: 3258859Last-Modified: Wed, 22 Feb 2012 13:52:13 GMTConnection: keep-aliveX-MyMasterHeader: setX-My2Heade: /adata/362.mp3Expires: Sat, 31 Mar 2012 15:43:04 GMTCache-Control: max-age=86400Accept-Ranges: bytes
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 inevery server{} block. Look at "listen" and "server_name" directives ineach 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 withinthat server{} block is being used for this request, then you couldlimit what you post to: the server{} block outside of all location{}s,plus the content of that one location{}. But that's probably more workthan is necessary.)If you can enable the debug log (will probably require rebuildingnginx), then you will see lots of information about what nginx thinksis happening.But posting the relevant part of the config file is the best way to makeit easy for people help you.f--Francis Daly fra...@daoine.org
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 theone 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 locationsthat don't otherwise set them.<snippage>include "/etc/cpnginx/custom/mega-sound.be";}
As above, because this is included last in the main file, the mp3 locationhere 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 haveit 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'tbe used for /adata/123.mp3, but will be used for /adata/123.html. You cantest 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 thatdoes 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 thatyour "all" more_set_headers directives did apply.HTTP/1.1 200 OKX-MyMasterHeader: setX-My2Header: /
This would match your original long location, so will be the file/home/megasoun/public_html/adata/362.mp3 if it exists, and proxied toport 8888 if it doesn't. Again, your "all" more_set_headers apply.HTTP/1.1 200 OKContent-Type: audio/mpegX-MyMasterHeader: setX-My2Heade: /adata/362.mp3If you remove "|mp3" from the first location; or just "include" this fileat the top instead of the bottom of the server{} block, then your custommp3 location would apply; and you should see your extra configurationbeing used. (Without "root" set right, though, you may just end up witha 404.)http://www.nginx.org/r/location for the details on how nginx chooseswhich one location{} block will be used for the current request, ifit's unclear.All the best,