Opened 6 years ago

Closed 6 years ago

#628 closed task (invalid)

nginx serving wrong certificate for another domain?

Reported by: Lorenzo Raffio Owned by:
Priority: minor Milestone:
Component: nginx-core Version: 1.7.x
Keywords: ssl certificate sni Cc:
uname -a:
nginx -V: 1.7.4


I have SNI installed and running fine. I have 6 websites hosted on the same VPS, same IP. 5 of them work just fine, every one is serving its correct ssl certificate.
But there's one that even if I'm setting ssl_certificate to the correct crt file related to that domain, is serving the certificate of another domain! (WTF?)

Here's the whole conf file for this domain:

fastcgi_cache_path			/var/www/ levels=1:2 inactive=60m;

server {

	### MAIN ###

	index					index.php;
	root					/var/www/;

	ssl_stapling				on;
	ssl_stapling_verify			on;
	ssl_trusted_certificate			/var/www/;
	ssl_certificate				/var/www/;
	ssl_certificate_key			/var/www/;
	access_log				/var/www/ combined gzip;
	error_log				/var/www/;
	charset					utf-8;
	rewrite					^/sitemap_index\.xml$ /index.php?sitemap=1 last;
	rewrite					^/([^/]+?)-sitemap([0-9]+)?\.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;
	location / {
		try_files $uri $uri/ /index.php?$args;

	location ~ \.php$ {
		fastcgi_cache_valid 200 5m;	
		fastcgi_cache_bypass $no_cache;
		fastcgi_no_cache $no_cache;
		try_files $uri =404;
		fastcgi_split_path_info ^(.+\.php)(/.+)$;			
		include fastcgi.conf;
		fastcgi_pass unix:/var/run/php5-fpm.sock;

	### CONFIGS ###
	include conf/h5bp.conf;
	include	conf/expires.conf;

	### TRIVIAL ###

	# Deny dot files:
	location ~ /\. {
		deny all;

	# favicon.ico not found
	location = /favicon.ico {
		access_log off;
		log_not_found off;

	# robots.txt not found
	location = /robots.txt { 
		access_log off; 
		log_not_found off; 

	### CACHE ###

	#Cache everything by default
	set $no_cache 0;

	#Don't cache POST requests
	if ($request_method = POST)
	    set $no_cache 1;

	#Don't cache if the URL contains a query string
	if ($query_string != "")
	    set $no_cache 1;

	#Don't cache the following URLs
	if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)")
	    set $no_cache 1;

	#Don't cache if there is a cookie called PHPSESSID
	if ($http_cookie ~* "PHPSESSID|comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in")
	    set $no_cache 1;


Change History (3)

comment:1 by Lorenzo Raffio, 6 years ago

Don't know if useful but I also add general nginx config.

And one other strange thing is that when for example I got to my wordpress login page over https and enter my login details, I'm redirected to the domain of the wrong certificate. Maybe is Strict Transport Security involved?

user						www-data;
worker_processes				auto;
worker_rlimit_nofile				8192;
error_log					/var/log/nginx/error.log info;
pid						/var/run/;

events {
  worker_connections				8000;
  multi_accept					on;

http {
	include					sites-enabled/*;
	index					index.php index.htm index.html;
	server_tokens				off; #don't send the nginx version number in error pages and Server header
	include					conf/mime.types;
	include					conf/geoip.conf;
	default_type				application/octet-stream;
	log_format				compression '$host $remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for"';
	access_log				/var/log/nginx/access.log compression buffer=32k;
	keepalive_timeout			40;
	types_hash_max_size			2048;
	server_names_hash_bucket_size		64;
	sendfile				on;
	tcp_nopush				on;
	tcp_nodelay				off;
	add_header				X-Frame-Options SAMEORIGIN; # config to don't allow the browser to render the page inside an frame or iframe and avoid clickjacking If you need to allow [i]frames, you can use SAMEORIGIN or even set an uri with ALLOW-FROM uri
	add_header				X-Content-Type-Options nosniff; # when serving user-supplied content, include a X-Content-Type-Options: nosniff header along with the Content-Type: header, to disable content-type sniffing on some browsers., currently suppoorted in IE > 8,, 'soon' on Firefox
	add_header				X-XSS-Protection "1; mode=block"; # This header enables the Cross-site scripting (XSS) filter built into most recent web browsers. It's usually enabled by default anyway, so the role of this header is to re-enable the filter for this particular website if it was disabled by the user.
	include					conf/cloudflare-ips.conf;
	real_ip_header				CF-Connecting-IP;
	real_ip_header				X-Forwarded-For;
	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;
	fastcgi_cache_key				"$scheme$request_method$host$request_uri";
	add_header				X-Cache $upstream_cache_status;
	client_max_body_size			15M;
	client_header_buffer_size		1k;
	client_body_buffer_size			16k;
	proxy_connect_timeout			90s;
	proxy_send_timeout			90s;
	proxy_read_timeout			90s;
	proxy_buffers				32 4k;
	large_client_header_buffers		4 8k;
	ssl_protocols				TLSv1 TLSv1.1 TLSv1.2; # disable SSLv3(enabled by default since nginx 0.8.19) since it's less secure then TLS
	ssl_prefer_server_ciphers		on; # enables server-side protection from BEAST attacks
	ssl_session_cache			shared:SSL:50m; # enable session resumption to improve https performance
	ssl_session_timeout			2h;
	add_header				Strict-Transport-Security "max-age=31536000; includeSubdomains;"; # enable HSTS(HTTP Strict Transport Security) to avoid ssl stripping
	ssl_dhparam				/etc/nginx/conf/dhparam.pem;
	gzip					on;
	gzip_static				on;
	gzip_buffers				16 8k;
	gzip_http_version			1.0;
	gzip_comp_level				5;
	gzip_min_length				256;
	gzip_proxied				any;
	gzip_vary				on;
	gzip_disable				"MSIE [1-6]\.(?!.*SV1)";
	#								text/html is always compressed by HttpGzipModule

comment:2 by Lorenzo Raffio, 6 years ago

Don't consider the Cloudflare related parameters. It's disabled for the domain.

comment:3 by Maxim Dounin, 6 years ago

Resolution: invalid
Status: newclosed

The server{} block in question doesn't have any listen directives in it, and hence will use listen 80 by default. It's not expected to be used for https requests, as https use port 443.

Note: See TracTickets for help on using tickets.