Question

I have an NGINX Port Problem

I’m using nginx with 3 server blocks. I’ve added a 4th server block, but since I didn’t had an active domain name, in “server_name” i’ve added my droplet’s IP address and I’ve also added “listen 81;” so I could easy access my development project.

Today I’ve bought a domain name, I’ve changed the “server_name” to the actual domain name, and removed “listen 81;” I’ve restarted nginx, and I’ve had problems.

First, when I tried to access the domain name, it returned an error and it came up like www.domain.com:81. When I tried to access the IP address on my droplet, it also came up like xx.xx.xx.xx:81.

My other 3 sites are functioning without any problems, and I cannot trace the problem with my newly added site. I’ve doubled checked the config but it’s identitcal to the other server blocks.

Can someone point me as to what might be the problem? Why is my droplet’s IP adress responding to 81, and why is my new domain responding to 81? And why I’m not getting any kind of response, just an error?

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

The new domain is loading your default website, have you removed this configuration?

When you installed WordPress on 188.226.235.21:81 the home and siteurl of WordPress were set to http://188.226.235.21:81

Now when pointing the domain name, WordPress is trying to redirect the domain to the IP:port URL.

Edit the wp-config.php file of this site and add the following code before /* That's all, stop editing! Happy blogging. */.

define( 'WP_SITEURL', 'http://cqlcontracting.com' );
define( 'WP_HOME', 'http://cqlcontracting.com' );

My droplet IP is 188.226.235.21 Other sites hosted at this server are: cqlinc.com; tehnika.mk; petarpetkovski.com. They are working proplerly.

Here’s the server block of the new website that is causing the problems. It is identical as the other sites except for the “server_name”.

Tried reinstalling nginx, restarting nginx, but no luck.

server {
	
	server_name cqlcontracting.com www.cqlcontracting.com;

	root /var/www/cqlinc.com/html;
	index index.php;

	set $cache_uri $request_uri;

	# POST requests and urls with a query string should always go to PHP
	if ($request_method = POST) {
		set $cache_uri 'null cache';
	}   
	if ($query_string != "") {
		set $cache_uri 'null cache';
	}   

	# Don't cache uris containing the following segments
	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 $cache_uri 'null cache';
	}   

	# Don't use the cache for logged in users or recent commenters
	if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") {
		set $cache_uri 'null cache';
	}

	# Use cached or actual file if they exists, otherwise pass request to WordPress
	location / {
		try_files /wp-content/cache/supercache/$http_host/$cache_uri/index.html $uri $uri/ /index.php ;
	}    

	location = /favicon.ico { log_not_found off; access_log off; }
	location = /robots.txt  { log_not_found off; access_log off; }

	location ~ .php$ {
		try_files $uri /index.php; 
		include fastcgi_params;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
	}

	# Cache static files for as long as possible
	location ~* .(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
		expires max; log_not_found off; access_log off;
	}
}