Apache cant restart because it already uses its port - linux

Whan I am trying to restart apache it shows an error:
(13)Permission denied: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
But when I am trying to check who uses it, it points to itself:
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 22656/apache2
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 22656/apache2
What is the problem here?

Free the catch memory and
Make sure you are not declaring Listen 80 twice in .conf files.
For example, you might have it both in ports.conf and inn sites-enabled/www.conf.
To find out, use: grep -ri listen /etc/apache2
Keep Listen 80 in just a single place.

Related

Why can't I talk to a service on tcp/3000 on my CentOS VPS

I'm trying to run a second web service on my VPS at port 3000.
On the VPS I run:
# php -S myhost.com:3000
and then in a browser, navigate to http://myhost.com:3000 but the browser times out and the service logs/outputs nothing.
If I run the service on port 80 (i.e., php -S myhost.com:80 and navigate to http://myhost.com), it works.
So firewall. Except that:
[root#spinal ~]# firewall-cmd --list-ports
3887/tcp 3000/tcp
(the 3887 is another service, which is working correctly.) And I rebooted the VPS after setting up port 3000 in the firewall. I reckon the service is listening correctly because:
[root#spinal ~]# netstat -tupl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:imap 0.0.0.0:* LISTEN 1907/dovecot
tcp 0 0 0.0.0.0:ciphire-data 0.0.0.0:* LISTEN 1876/sshd
tcp 0 0 0.0.0.0:http 0.0.0.0:* LISTEN 1903/nginx: master
tcp 0 0 0.0.0.0:urd 0.0.0.0:* LISTEN 2004/master
tcp 0 0 myhost.com:hbci 0.0.0.0:* LISTEN 2206/php
tcp 0 0 localhost.loca:postgres 0.0.0.0:* LISTEN 1908/postgres
tcp 0 0 0.0.0.0:smtp 0.0.0.0:* LISTEN 2004/master
tcp 0 0 0.0.0.0:https 0.0.0.0:* LISTEN 1903/nginx: master
tcp 0 0 0.0.0.0:imaps 0.0.0.0:* LISTEN 1907/dovecot
tcp 0 0 localhost.lo:cslistener 0.0.0.0:* LISTEN 1878/php-fpm: maste
tcp6 0 0 [::]:imap [::]:* LISTEN 1907/dovecot
tcp6 0 0 [::]:ciphire-data [::]:* LISTEN 1876/sshd
tcp6 0 0 [::]:urd [::]:* LISTEN 2004/master
tcp6 0 0 [::]:smtp [::]:* LISTEN 2004/master
tcp6 0 0 [::]:imaps [::]:* LISTEN 1907/dovecot
I can however connect locally. This works, when run on the VPS:
$ curl http://myhost.com:3000
so that again points at the firewall. But disabling the firewall doesn't help:
# systemctl stop firewalld
so it could be a DNS problem: my browser and the VPS differ on what myhost.com resolves-to. Except that, as mentioned above, switching to port 80 solves the problem. So it's something to do with coming-in on port 3000, from outside. But not firewalld.
The question at Can't reach nodejs on port 3000 from external on CentOS 7 is close to mine, but isn't conclusively answered.
I feel pretty stupid. It was a firewall; not on the VPS, but on my local network. When I tried it on a machine that doesn't go through my local network, it worked. I hope my public confession helps someone else.

Apache can't start "could not bind to address [::]:443" though no process is using it, and netcat can openit

my version of apache
Server version: Apache/2.4.6 (CentOS)
Server built: Apr 20 2018 18:10:38
when I run the command lsof -i :443 it returns nothing
but if I try to run apache (directly by running httpd I got the error, I verified with ps aux that there was no previous httpd/apache process already running)
(98)Address already in use: AH00072: make_sock: could not bind to address [::]:443
However if i try to run a netcat process on 443 nc 0.0.0.0 -l 443 , it does open and I can send data
I'm a bit lost on what could be the problem ?
Found it
Listen 443 was present two times among the different configuration files of apache
it's a pity apache does not have a more explicit error/warning message (i.e "option defined two times" etc.)
It seems another process is using port 443 on your server.
netstat -anp | grep 443
output will be
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN
disable port 443 and start
systemctl start httpd.service

Passenger, Plesk and Node.js: address already in use

My question is about getting Phusion Passenger and Plesk Onyx 17.5.3 to work together nicely. I have a new server running Ubuntu 16.04.
I am following the official Phusion Passenger tutorial on deploying a Node.js app, and I have followed it successfully to the point where I need to tell Passenger to listen on port 80.
Here are my steps:
With my registrar, I set up a DNS entry for the subdomain pass.domain.com
In the Plesk interface, I define the new subdomain
If I visit http://pass.domain.com in my browser, I get the default Plesk web page.
I follow the "Phusion Passenger: Node.js tutorial" until I reach this command:
sudo passenger start --port 80 --user someusername --environment production --daemonize
Note: I am using a valid custom user name in the place of `someusername'.
I get this error:
Could not start the Nginx engine:
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
It appears that Plesk is already serving the default web page at this address, so Phusion Passenger cannot access it. What files do I need to add or edit to get Plesk to release the address so that Passenger can use it?
EDIT 4: I have found this question which describes similar symptoms. However the OP is using Meteor Up and I am using Passenger. His solution was to get Meteor Up to tell Node.js to run on port 3001, and get nginx to listen on port 80 and proxy requests to port 3001. I had understood that Phusion Passenger already does something similar under the hood.
Is there a way to modify the passenger start command to clarify this?
OLDER EDITS
EDIT 1: In response to #TarunLalwali, here is the output of sudo netstat -plnat on this server:
$ sudo netstat -plnat
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:4190 0.0.0.0:* LISTEN 15234/dovecot
tcp 0 0 127.0.0.1:12768 0.0.0.0:* LISTEN 15654/psa-pc-remote
tcp 0 0 0.0.0.0:993 0.0.0.0:* LISTEN 15234/dovecot
tcp 0 0 0.0.0.0:995 0.0.0.0:* LISTEN 15234/dovecot
tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN 2293/mongod
tcp 0 0 0.0.0.0:110 0.0.0.0:* LISTEN 15234/dovecot
tcp 0 0 0.0.0.0:143 0.0.0.0:* LISTEN 15234/dovecot
tcp 0 0 127.0.0.1:783 0.0.0.0:* LISTEN 1315/.spamassassin
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 26659/nginx
tcp 0 0 0.0.0.0:8880 0.0.0.0:* LISTEN 23894/config
tcp 0 0 0.0.0.0:465 0.0.0.0:* LISTEN 2142/master
tcp 0 0 172.17.0.1:53 0.0.0.0:* LISTEN 17312/named
tcp 0 0 94.76.206.212:53 0.0.0.0:* LISTEN 17312/named
tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 17312/named
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1413/sshd
tcp 0 0 0.0.0.0:3000 0.0.0.0:* LISTEN 12563/passenger-sta
tcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN 17312/named
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 2142/master
tcp 0 0 94.76.206.212:443 0.0.0.0:* LISTEN 26659/nginx
tcp 0 0 0.0.0.0:8443 0.0.0.0:* LISTEN 23894/config
tcp 0 0 94.76.206.212:993 92.130.47.95:49994 ESTABLISHED 15322/imap-login
tcp 0 0 127.0.0.1:51168 127.0.0.1:12768 TIME_WAIT -
tcp 0 0 94.76.206.212:25 200.188.141.75:51400 TIME_WAIT -
tcp 0 188 94.76.206.212:22 92.130.47.95:34414 ESTABLISHED 4035/sshd: blacksla
tcp6 0 0 :::4190 :::* LISTEN 15234/dovecot
tcp6 0 0 :::993 :::* LISTEN 15234/dovecot
tcp6 0 0 :::995 :::* LISTEN 15234/dovecot
tcp6 0 0 :::7080 :::* LISTEN 26432/apache2
tcp6 0 0 :::7081 :::* LISTEN 26432/apache2
tcp6 0 0 127.0.0.1:3306 :::* LISTEN 10040/mysqld
tcp6 0 0 :::106 :::* LISTEN 1532/xinetd
tcp6 0 0 :::110 :::* LISTEN 15234/dovecot
tcp6 0 0 :::143 :::* LISTEN 15234/dovecot
tcp6 0 0 ::1:783 :::* LISTEN 1315/.spamassassin
tcp6 0 0 2a02:af8:1:900::3860:80 :::* LISTEN 26659/nginx
tcp6 0 0 :::8880 :::* LISTEN 23894/config
tcp6 0 0 :::465 :::* LISTEN 2142/master
tcp6 0 0 :::53 :::* LISTEN 17312/named
tcp6 0 0 :::21 :::* LISTEN 1532/xinetd
tcp6 0 0 :::22 :::* LISTEN 1413/sshd
tcp6 0 0 :::25 :::* LISTEN 2142/master
tcp6 0 0 2a02:af8:1:900::386:443 :::* LISTEN 26659/nginx
tcp6 0 0 :::8443 :::* LISTEN 23894/config
Note: I have already asked about this issue on the Plesk forum, but it has received no response. I am hoping that asking the Phusion Passenger community here will be more productive. Once I have a working solution, I will post a link from the Plesk forum to the answer here.
Thanks in advance for your insights,
James
EDIT 2: Following #TarunLalwali's advice, I tried stopping nginx, but this produced an unknown error:
$ sudo nginx -s stop
$ sudo passenger start --port 80 --user node --environment production --daemonize
Could not start the Nginx engine:
nginx: [alert] Unable to start the Phusion Passenger watchdog because it encountered the following error during startup: Unable to start the Passenger core: it seems to have crashed during startup for an unknown reason, with exit code 1 (-1: Unknown error)
EDIT 3: Attempting to disable nginx server-wide before invoking Passenger:
$ sudo systemctl disable nginx
Synchronizing state of nginx.service with SysV init with /lib/systemd/systemd-sysv-install...
Executing /lib/systemd/systemd-sysv-install disable nginx
insserv: warning: current start runlevel(s) (empty) of script `nginx' overrides LSB defaults (2 3 4 5).
insserv: warning: current stop runlevel(s) (0 1 2 3 4 5 6) of script `nginx' overrides LSB defaults (0 1 6).
$ systemctl status nginx
* nginx.service - Startup script for nginx service
Loaded: loaded (/lib/systemd/system/nginx.service; disabled; vendor preset: enabled)
Active: inactive (dead)
$ sudo passenger start --port 80 --user node --environment production --daemonize
Could not start the Nginx engine:
nginx: [alert] Unable to start the Phusion Passenger watchdog because it encountered the following error during startup: Unable to start the Passenger core: it seems to have crashed during startup for an unknown reason, with exit code 1 (-1: Unknown error)
You mention that you need the system Nginx (at port 80) to run other subdomains on the server.
Passenger Standalone can coexist peacefully with a system Nginx using two steps:
Run it on a non-conflicting port, for example the default 3000:
sudo passenger start --port 3000 --user someusername --environment production --daemonize
For the domain that you want Passenger to server, tell the system Nginx to proxy to Passenger.
proxy_pass http://localhost:3000;
Remember to reload/restart Nginx to activate the config.
How to do step 2 exactly in Plesk is a question best asked on the Plesk forum, but from the Passenger point of view this setup should work.

Unable to access apache page on Linux Azure VM

I've setup a linux VM in Azure. I've added incoming port access to the current listening port on Apache. I've also done a curl localhost on the VM and see the apache html text. I hit the public IP of the VM and get nothing. Any ideas?
According to your description, please check those settings:
1. Please check Azure VM's NSG settings, make sure we have add port to inbound rules:
2. Vnet-->subnet's security group settings:
3. Check which port apache listening on:
netstat -ant
root#ubuntu:~# netstat -ant
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 10.1.0.4:55870 191.237.32.134:443 TIME_WAIT
tcp 0 0 10.1.0.4:55874 191.237.32.134:443 TIME_WAIT
tcp 0 0 10.1.0.4:55876 191.237.32.134:443 TIME_WAIT
tcp 0 0 10.1.0.4:55868 191.237.32.134:443 TIME_WAIT
tcp 0 0 10.1.0.4:57772 168.63.129.16:80 TIME_WAIT
tcp 0 0 10.1.0.4:57766 168.63.129.16:80 TIME_WAIT
tcp 0 36 10.1.0.4:22 167.220.255.8:53651 ESTABLISHED
tcp6 0 0 :::80 :::* LISTEN
tcp6 0 0 :::22 :::* LISTEN
By the way, for test please disable ufw with this command ufw disable, then try to access the public IP address.
Update:
I follow those steps to modify apache default port:
1.Modify ports.conf, change port 80 to 80:
root#ubuntu:/etc/apache2# vi ports.conf
Listen 90
<IfModule ssl_module>
Listen 443
2.Add ServerName localhost to /etc/apache2/apache2.conf
root#ubuntu:/etc/apache2# vi /etc/apache2/apache2.conf
# Global configuration
#
ServerName localhost
3.Modify default port in /etc/apache2/sites-enabled/000-default.conf
root#ubuntu:/etc/apache2# vi /etc/apache2/sites-enabled/000-default.conf
<VirtualHost *:90>
4.Add inbound rule to Network Security Group:
By the way, to troubleshoot this issue, we can follow those steps:
1.Login this VM and use curl to test apache2:
curl localhost:90
2.Use your PC to telnet this VM's public IP and port 90
telnet xx.xx.xx.xx 90
If you can't telnet this port, please check your NSG settings and subnet's security group settings.
Here is my result, it works for me:
root#ubuntu:/etc/apache2# netstat -ant | grep 90
tcp6 0 0 :::90 :::* LISTEN

Linux Centos 6 Some how filtered port 80 + broke Apache 2

I have magically been able to break port 80 / Apache server when following a guide to install PHPMyAdmin (http://www.krizna.com/centos/installing-apache2-mysql-server-php-centos-6-lamp/#apache)
Prior to me to starting the guide, Apache 2 was working for me (was able to view pages and see the default blue one)
I followed the guide down to Step 4 under "PHP installation" and went to check the page and I was getting the following error (note: I skipped Mysql installation since I have it already installed and "Testing your page" in the Apache section since I had it working prior).
ERROR
The requested URL could not be retrieved
The following error was encountered while trying to retrieve the URL: http://`192.168.141.22`/
Read Error
The system returned: (104) Connection reset by peer
An error condition occurred while reading data from the network. Please retry your request.
Your cache administrator is webmaster.
Generated Wed, 03 Jul 2013 19:04:56 GMT by tx22rrpep4da (hpm/3.0.55)
I tried to uninstall (yum erase) httpd and php and re-install and no success.
I did an nmap and it shows 80/tcp filtered http.
I even disabled/stopped IP tables incase that was the issue, no luck. I have other things like TS3 running on other ports fine.
Restarted the dedicated server.
netstat -tulpn
te PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 25896/httpd
tcp 0 0 0.0.0.0:30033 0.0.0.0:* LISTEN 2967/./ts3server_li
tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 2736/named
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2798/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2873/master
tcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN 2736/named
tcp 0 0 0.0.0.0:10011 0.0.0.0:* LISTEN 2967/./ts3server_li
tcp 0 0 ::1:53 :::* LISTEN 2736/named
tcp 0 0 :::22 :::* LISTEN 2798/sshd
tcp 0 0 ::1:953 :::* LISTEN 2736/named
udp 0 0 0.0.0.0:9987 0.0.0.0:* 2967/./ts3server_li
udp 0 0 127.0.0.1:53 0.0.0.0:* 2736/named
udp 0 0 ::1:53 :::* 2736/named
I had a few other people test the IP in case it was just my connection but they all got the same as well (IP: 192.168.141.22 )
Really hoping I can get this fixed with out doing something over the top like wiping and re-installing centos 6.
The netstat command is showing that Apache is in-deed listening on the following IP & port:
0 0.0.0.0:80
If you want reach Apache in 192... ip, then you need to edit one of the .conf files that has the "Listen" directive(normally in /etc/httpd/conf.d/ports.conf or the main .conf file) and either put in the ip or remove all ips so Apache can listen on all interfaces available in the machine.

Resources