I have a periodical problem in a server with Plesk, the Port 80 is not listened but 7080 is listened so the websites do not respond on the Port 80.
#netstat -tlpn | grep :80
#netstat -tlpn | grep :7080
tcp 0 0 :::7080 :::* LISTEN 3009/httpd
# plesk sbin nginxmng -s
Enabled
I resolve this problem executing the following commands but after few minutes the problem returns periodically:
pkill -9 nginx
# service nginx start
Starting nginx: [ OK ]
# /usr/local/psa/admin/bin/nginxmng -d
# /usr/local/psa/admin/bin/nginxmng -e
# service nginx restart
Starting nginx: [ OK ]
Source: https://support.plesk.com/hc/en-us/articles/213926725-Websites-do-not-respond-on-80-port-but-respond-properly-on-7080-port
How can i finally fix this error? I am thinking to add a crontab running the commands that i have used to solve the error but i think that it is not a good idea.
Related
I am trying to connect my flask app to Nginx and Gunicorn, based on this tutorial: How To Serve Flask Applications with Gunicorn and Nginx on Ubuntu 14.04.
I am getting a 502 Bad Gateway
var/log/nginx
2017/10/16 21:17:04 [crit] 11284#0: *8 connect() to unix:/home/myproject/myproject.sock failed (2: No such file or directory) while connecting to upstream, client: <myIP>, server: <myIP>, request: "GET / HTTP/1.1", upstream: "http://unix:/home/myproject/myproject.sock:/", host: "<myIP>"
It seems like Nginx couldn't find the myproject.sock file, and I don't know why my upstart script wouldn't create one based on the tutorial. Any guidance is greatly appreciated.
Below are my files:
/home/myproject/myproject.py
from flask import Flask
application = Flask(__name__)
#application.route("/")
def hello():
return "<h1 style='color:blue'>Hello There!</h1>"
if __name__ == "__main__":
application.run(host='0.0.0.0')
/home/myproject/wsgi.py
from myproject import application
if __name__ == "__main__":
application.run()
/etc/init/myproject.conf
note: I ran the cd and exec command in the file below for testing purposes and it works fine.
description "Gunicorn application server running myproject"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
setuid www-data
setgid www-data
script
cd /home/myproject
exec gunicorn --bind unix:myproject.sock -m 007 wsgi
end script
/etc/nginx/sites-available this is symlinked to sites-enabled
server {
listen 80;
server_name <myIPaddressHere>;
location / {
include proxy_params;
proxy_pass http://unix:/home/myproject/myproject.sock;
}
}
Debugging Steps I took:
(1) I checked that the upstart script is running
$ sudo status myproject
myproject start/running, process 22476
(2) Nginx is running
(3) Weird, I don't see my myproject.sock
# netstat -lpn
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:80 0.0.0.0:* LISTEN 11279/nginx
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1304/sshd
tcp6 0 0 :::80 :::* LISTEN 11279/nginx
tcp6 0 0 :::22 :::* LISTEN 1304/sshd
Active UNIX domain sockets (only servers)
Proto RefCnt Flags Type State I-Node PID/Program name Path
unix 2 [ ACC ] SEQPACKET LISTENING 7190 386/systemd-udevd /run/udev/control
unix 2 [ ACC ] STREAM LISTENING 8774 1120/acpid /var/run/acpid.socket
unix 2 [ ACC ] STREAM LISTENING 6541 1/init #/com/ubuntu/upstart
unix 2 [ ACC ] STREAM LISTENING 8339 859/dbus-daemon /var/run/dbus/system_bus_socket
[Solved] A mentor of mine pointed this out.
www-data/www-data can not write to /home/myproject/
Either write into tmp or choose a user/group that has more permissions.
I chose to write to /tmp
description "Gunicorn application server running myproject"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
setuid www-data
setgid www-data
script
cd /home/myproject
exec gunicorn --bind unix:/tmp/myproject.sock -m 007 wsgi
end script
And the Nginx file looks like this:
server {
listen 80;
server_name <ip>;
location / {
include proxy_params;
proxy_pass http://unix:/tmp/myproject.sock;
}
}
I am trying to setup the flume agent to collect the log events from Rsyslog, but I dont have root permission/sudoer to figure out which port syslog is running on/ and where it is running on TCP or UDP so I can configure flume agent accordingly.
Is there any way to know exactly what is the port that Rsyslog deamon running on?
Below are command that I have used to identify Rsyslog Deamon process
ldnpsr000001131$ ps -ef | grep syslog
root 4874 1 0 Feb04 ? 00:00:14 /sbin/rsyslogd -i /var/run/syslogd.pid -c 4
You may try netstat -natupel |grep syslog and you'll get all connections : active and listening
If nginx init.d script does not take status option (like Apache) - how could I possibly know if it is running or not? I can verify nginx process exists but it does not tell much.
Except checking that process exists, you can always check netstat -tulpn | grep nginx
# netstat -tulpn | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 4158/nginx.conf
I want to deploy my flask service in a server with centOS 7. So I followed this tutorial - https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-uwsgi-and-nginx-on-centos-7 .
After runnning systemctl start nginx command, I got this error:
nginx: [emerg] bind() to 0.0.0.0:5000 failed (13: Permission denied)
My nginx.conf file:
server {
listen 5000;
server_name _;
location / {
include uwsgi_params;
uwsgi_pass unix:/root/fiproxy/fiproxyproject/fiproxy.sock;
}
}
Note: flask service and wsgi work ok. And I've tried to run nginx with superuser and the error remains.
After search a lot in Internet, I found a solution to my problem.
I ran this command to get all used ports in my machine: semanage port -l.
After that, I filtered the output with: semanage port -l | grep 5000.
I realized that this port 5000 is used by commplex_main_port_t, I searched in speedguide and I found: 5000 tcp,udp **UPnP**.
Conclusion, maybe my problem was bind a standard port.
To add your desired port use this command:
sudo semanage port -a -t http_port_t -p tcp [yourport]
Now run nginx with sudo:
sudo systemctl stop nginx
sudo systemctl start nginx
The Nginx master process needs root permission. Because it needs bind port.
You need start Nginx under root user.
Then you can define the user of child processes in nginx.conf.
Is there any command which checks that a certain process is listening to a port.
I have tried check_tcp but it does not output which process is listening to a port
Its output was:
TCP OK - 0.000 second response time on port 8443|time=0.000421s;;;0.000000;10.000000
I didn't see anything on the Nagios Plugins Exchange to meet your needs, so I wrote one to be used with NRPE.
https://github.com/jlyoung/nagios_check_listening_port_linux
Output looks like this:
[root#joeyoung.io ~]# python /usr/lib/nagios/plugins/nagios_check_listening_port_linux.py -n nginx -p 80
OK. nginx found listening on port 80 for the following address(es): [0.0.0.0] | 'listening_on_expected_port'=1;;;;
[root#joeyoung.io ~]# python /usr/lib/nagios/plugins/nagios_check_listening_port_linux.py -n nginx -p 9999
CRITICAL - No process named nginx could be found listening on port 9999 | 'listening_on_expected_port'=0;;;;