Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Today I set up a self-signed SSL certificate for my Wordpress sites via my Cent OS Nginx VPS. Because I want to use HTTPS only for Wordpress backend.

This is my vhost nginx configuration file (file in here). After I reload the nginx, now this site only works HTTPS. HTTP display Unable to connect error.

Then I run a telnet command via SSH, then it shows following output.

root@host [~]# telnet 80
telnet: connect to address Connection refused

I didn't block the port 80. If I disabled CSF, nothing happens. If I removed following codes in sites-enabled config file both HTTP and HTTPS are working. (I don't know how much it's secure and correct)

    listen ssl;

    ssl on;  
    ssl_certificate /opt/pifpm/ssl/server.crt;
    ssl_certificate_key /opt/pifpm/ssl/server.key;

Could someone please tell me how do I use both HTTP and HTTPS in this virtual host? Is it secure removed above SSL certificate codes from my site's nginx configuration file and use HTTPS (because SSL working without that settings codes)?


share|improve this question

Do you have also listen; in the server block?

You should remove ssl on; directive. That makes the whole server block as an SSL block, which is not what you want. The ssl directive on the current listen line is enough.

share|improve this answer
Yes, I added listen; as well as listen; which is mentioned in Nginx doc in here for use single server to handles both HTTP and HTTPS requests. Thanks I'll remove ssl on; directive and let you know it success. – chris Mar 20 '14 at 2:41
Update, After I removed listen; and use only listen;nothing happened. It only works HTTPS. Non SSL giving me Unable to connect – chris Mar 20 '14 at 2:55

I managed to fix this issue by myself.

When I try to restart the nginx, I can see following warning.

root@host [~]# sudo service nginx restart
Stopping nginx:                                            [FAILED]
Starting nginx: nginx: [emerg] bind() to failed (98: Address already in use)
nginx: [emerg] bind() to failed (98: Address already in use)
nginx: [emerg] bind() to failed (98: Address already in use)
nginx: [emerg] bind() to failed (98: Address already in use)
nginx: [emerg] bind() to failed (98: Address already in use)
nginx: [emerg] still could not bind()

Then, in SSH i run sudo fuser -k 443/tcp and then restart the nginx using service nginx start. Then everything works fine. However, every VPS reboot, I again face HTTP not working issue.

I use the cpXstack plugin to install Nginx in WHM. If this plugin changed the Apache HTTP port 80, it doesn't change the Apache port 443. Therefore, I manually changed Apache port 443 to 1443 and restart the Apache. Now this issue completely fixed and both HTTP and HTTPS working in every VPS reboot.

Don't know what's the reason if none of the VPS services doesn't use port 80, HTTP not working.

share|improve this answer
You should remove Apache if you don't use it. – Tero Kilkanen Mar 20 '14 at 10:04
This is WHM cPanel server. So it'll not cause any issue? – chris Mar 20 '14 at 15:05
Unfortunately I don't know about WHM / cPanel, so I cannot help with that. Doesn't WHM cPanel have any mechanism to replace Apache with nginx? – Tero Kilkanen Mar 20 '14 at 23:44
No, WHM official support Apache. But we can install Nginx separately, like I do. Anyway thanks Tero your support. – chris Mar 21 '14 at 16:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.