I have an NGINX Port Problem

November 5, 2014 3.3k views

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?

1 comment
  • We don't know - you gave us no config and even hid the IP and domain name so we can't possibly check ourselves.

    It's likely that you simply didn't remove the listen directive, forgot to restart nginx, or you are not troubleshooting the issue correctly.

2 Answers

My droplet IP is
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;

  • Hi,

    That block is not causing the issue. It has to be another block.

    I have verified and your server is indeed answering on port 81, I'm not getting any sort of error as you mentioned. What error were you getting?

    Do you have only one web server on the machine?

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

When you installed WordPress on the home and siteurl of WordPress were set to

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' );
Have another answer? Share your knowledge.