nginx is installed but site does not load - linux

I installed LEMP with this tutorial I have done all it says but when I enter my server ip address in my browser it takes some time to load the page and it seems like my browser is doing some processes to load the page but at last the page is blank.
I'v checked all the installation again and they were all installed.
I'v installed apache at the past and I know for apache server if you enter server ip address it shows " apache is functioning " but It's my first time installing nginx ; I want to install DirectAdmin and I don't know nginx is installed or not.
If anyone is familiar with nginx and can help me, I'll be apreciate that.
Update: When I use service nginx status it shows nginx is running.
Update: Flowing are the results of my checkings:
Results of netstat -tulpn | grep :80 :
tcp 0 0 0.0.0.0:80 0.0.0.0:* LIST EN 10302/nginx
Results of ps aux | grep nginx :
nginx 8556 0.0 0.0 222416 3552 ? S 09:04 0:00 php-fpm: pool w ww
nginx 8557 0.0 0.0 222416 3552 ? S 09:04 0:00 php-fpm: pool w ww
nginx 8558 0.0 0.0 222416 3552 ? S 09:04 0:00 php-fpm: pool w ww
nginx 8559 0.0 0.0 222416 3552 ? S 09:04 0:00 php-fpm: pool w ww
nginx 8560 0.0 0.0 222416 3552 ? S 09:04 0:00 php-fpm: pool w ww
root 10302 0.0 0.0 96032 1980 ? Ss 09:11 0:00 nginx: master p rocess /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx 10304 0.0 0.0 96436 2692 ? S 09:11 0:00 nginx: worker p rocess
nginx 10305 0.0 0.0 96436 2692 ? S 09:11 0:00 nginx: worker p rocess
nginx 10306 0.0 0.0 96436 2660 ? S 09:11 0:00 nginx: worker p rocess
nginx 10307 0.0 0.0 96436 2672 ? S 09:11 0:00 nginx: worker p rocess
root 12564 0.0 0.0 103312 856 pts/0 S+ 09:59 0:00 grep nginx

FIIIIINNNNNNAAAAAALLLLLLLY I Found the problem!
The problem was with my firewall.
If anyone else has the same problem it may be the firewall settings problem like mine So Do the flowing to fix this:
vim /etc/sysconfig/iptables
in the opened file find this line :
-A INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT
Check that --dport 80 is set to the port that you entered in /etc/nginx/conf.d/default.conf if its something else like --dport 22 change it to your default port.
Update:
After you changed the port you should run this code:
service iptables restart
And this is the page shows nginx is running :

Related

Multiple apache and finding its ports

The following command
[cuser#vdev-b7-5461-4f3c-9d98-7fc3ec6 kafka]$ ps aux|grep apache
apache 3967 0.0 0.0 175412 3192 ? S 03:40 0:00 /usr/sbin/httpd -k start
apache 3968 0.0 0.0 175412 3192 ? S 03:40 0:00 /usr/sbin/httpd -k start
apache 3969 0.0 0.0 175412 3192 ? S 03:40 0:00 /usr/sbin/httpd -k start
apache 3970 0.0 0.0 175412 3192 ? S 03:40 0:00 /usr/sbin/httpd -k start
apache 3971 0.0 0.0 175276 2700 ? S 03:40 0:00 /usr/sbin/httpd -k start
apache 3972 0.0 0.0 175276 2700 ? S 03:40 0:00 /usr/sbin/httpd -k start
apache 3974 0.0 0.0 175412 3188 ? S 03:40 0:00 /usr/sbin/httpd -k start
apache 3975 0.0 0.0 175276 2696 ? S 03:40 0:00 /usr/sbin/httpd -k start
clduser 9566 0.0 0.0 103244 844 pts/1 S+ 16:41 0:00 grep apache
There are multiple apache process running in my machine. Is there a way for me to determine the files/directory each of these process uses to run it?
Also, would like to know the ports that they are using?
[user#vdev-37-5461-4f3c-9d98-7af28dfc3ec6 kafka]$ netstat -tulpn|grep 80
(No info could be read for "-p": geteuid()=500 but you should be root.)
tcp 0 0 :::80 :::* LISTEN -
This above command shows port 80 is being used but I want to know what process is using it?
[duser#vpsq-dev-4ac0b737-5461-4f3c-9d98-7af28dfc3ec6 kafka]$ find / -iname apache 2>/dev/null
/opt/logstash/vendor/bundle/jruby/1.9/gems/jruby-kafka-1.4.0-java/lib/org/apache
/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-output-elasticsearch-0.1.18-java/lib/org/apache
/opt/logstash/vendor/bundle/jruby/1.9/gems/jruby-kafka-1.1.2-java/lib/org/apache
/home/duser/logstash-1.5.0.rc2/vendor/bundle/jruby/1.9/gems/logstash-output-elasticsearch-0.1.18-java/lib/org/apache
/home/duser/logstash-1.5.0.rc2/vendor/bundle/jruby/1.9/gems/jruby-kafka-1.1.2-java/lib/org/apache

Can't stop/restart Apache2 service

Trying to stop Apache2 service, but get PID error:
#service apache2 stop
[FAIL] Stopping web server: apache2 failed!
[....] There are processes named 'apache2' running which do not match your pid file which are left untouched in the name of safety, Plea[warnview the situation by hand. ... (warning).
Trying to kill, those processes:
#kill -9 $(ps aux | grep apache2 | awk '{print $2}')
but they get re-spawned again:
#ps aux | grep apache2
root 19279 0.0 0.0 4080 348 ? Ss 05:10 0:00 runsv apache2
root 19280 0.0 0.0 4316 648 ? S 05:10 0:00 /bin/sh /usr/sbin/apache2ctl -D FOREGROUND
root 19282 0.0 0.0 91344 5424 ? S 05:10 0:00 /usr/sbin/apache2 -D FOREGROUND
www-data 19284 0.0 0.0 380500 2812 ? Sl 05:10 0:00 /usr/sbin/apache2 -D FOREGROUND
www-data 19285 0.0 0.0 380500 2812 ? Sl 05:10 0:00 /usr/sbin/apache2 -D FOREGROUND
And though the processes are running i can't connect to the server on port 80. /var/log/apache2/error.log.1 has no new messages when i do the kill -9.
Before I tried to restart everything worked perfectly.
Running on Debian: Linux adara 3.2.0-4-amd64 #1 SMP Debian 3.2.54-2 x86_64 GNU/Linux
UPD:
also tried apache2ctl:
#/usr/sbin/apache2ctl -k stop
AH00526: Syntax error on line 76 of /etc/apache2/apache2.conf:
PidFile takes one argument, A file for logging the server process ID
Action '-k stop' failed.
The Apache error log may have more information.
but there is no pid file in /var/run/apache2
I'm new to linux, looks like it has to do something with startup scripts, but can't figure out what exactly.
Below is the command to find out the process running on port 80
lsof -i tcp:80
Kill the process with PID.Restart the system once to check if their is any start up script executing and using the Port 80 which is preventing you to start your service.
For start up scripts you can check
/etc/init.d/ or /etc/rc.local or crontab - e
You can try Apache official documentation for stop/restart operations.
link

PHP-FPM processes gets stuck out of sudden

While working on upgrading to PHP 5.5 I've faced a problem with php-fpm.
I've created a new web node with the new PHP version and I'm signing it in on the load balancer to test it in prod. Everything works out fine until a lot of php-fpm processes gets stuck out of sudden (after ~1 hour). Hereafter I receives timeouts.
I've changed distribution from Debian to Ubuntu and upgraded to PHP 5.5. Besides that the new server is the same as before (when everything worked/works).
I've tried signing in two new web nodes and they will get stuck at the same time.
I think it can be related to sudden slow responses from database (since that's the only thing they share).
However, I would like php-fpm not to crash, so it will work when database is OK again.
To fix it now I can restart php-fpm service but that's not a solid plan.
ps aux | grep php shows me:
root 13919 0.0 0.4 423472 19736 ? Ss Dec08 0:10 php-fpm: master process (/etc/php5/fpm/php-fpm.conf)
www-data 14087 0.0 3.1 474972 127284 ? S Dec08 0:54 php-fpm: pool www
www-data 14088 0.0 2.3 446944 94956 ? S Dec08 0:50 php-fpm: pool www
www-data 14089 0.1 2.2 443816 92644 ? S Dec08 1:03 php-fpm: pool www
www-data 14090 0.0 3.0 474208 124716 ? S Dec08 0:44 php-fpm: pool www
www-data 14092 0.0 3.1 478284 129060 ? S Dec08 0:41 php-fpm: pool www
www-data 14099 0.0 2.5 459700 105224 ? S Dec08 0:14 php-fpm: pool www
www-data 14111 0.0 2.0 439876 84952 ? S Dec08 0:06 php-fpm: pool www
www-data 14114 0.0 0.4 427220 18472 ? S Dec08 0:00 php-fpm: pool www
www-data 14115 0.0 0.4 427220 18380 ? S Dec08 0:00 php-fpm: pool www
www-data 14116 0.0 0.4 427184 18936 ? S Dec08 0:00 php-fpm: pool www
www-data 14117 0.0 0.4 427204 18904 ? S Dec08 0:00 php-fpm: pool www
www-data 14118 0.0 0.4 427220 18372 ? S Dec08 0:00 php-fpm: pool www
www-data 14119 0.0 0.4 427184 18832 ? S Dec08 0:00 php-fpm: pool www
www-data 14120 0.0 0.4 427188 18960 ? S Dec08 0:00 php-fpm: pool www
www-data 14121 0.0 0.4 427220 18384 ? S Dec08 0:00 php-fpm: pool www
www-data 14122 0.0 0.4 427200 18932 ? S Dec08 0:00 php-fpm: pool www
www-data 14123 0.0 0.4 427236 18488 ? S Dec08 0:00 php-fpm: pool www
www-data 14124 0.0 0.4 427220 18392 ? S Dec08 0:00 php-fpm: pool www
www-data 14125 0.0 0.4 427220 18384 ? S Dec08 0:00 php-fpm: pool www
www-data 14126 0.0 0.4 427204 18820 ? S Dec08 0:00 php-fpm: pool www
www-data 14127 0.0 0.4 427220 18484 ? S Dec08 0:00 php-fpm: pool www
www-data 14128 0.0 0.4 427204 18920 ? S Dec08 0:00 php-fpm: pool www
www-data 14129 0.0 0.4 427188 18904 ? S Dec08 0:00 php-fpm: pool www
www-data 14130 0.0 0.4 427220 18372 ? S Dec08 0:00 php-fpm: pool www
www-data 14131 0.0 0.4 427188 18920 ? S Dec08 0:00 php-fpm: pool www
www-data 14132 0.0 0.4 427220 18372 ? S Dec08 0:00 php-fpm: pool www
www-data 14133 0.0 0.4 427204 18936 ? S Dec08 0:00 php-fpm: pool www
www-data 14134 0.0 0.4 427220 18388 ? S Dec08 0:00 php-fpm: pool www
www-data 14135 0.0 0.4 427220 18368 ? S Dec08 0:00 php-fpm: pool www
www-data 14136 0.0 0.4 427184 18936 ? S Dec08 0:00 php-fpm: pool www
As you can see 24 processes has been running for 0 seconds (htop tells me it's around 2ms). They will stay like that forever. All of them appeared at the same time.
My config:
pid = /var/run/php5-fpm.pid
error_log = /var/log/php5-fpm.log
log_level = debug
user = www-data
group = www-data
listen = 127.0.0.1:9000
pm = dynamic
pm.max_children = 30
pm.start_servers = 5
pm.min_spare_servers = 3
pm.max_spare_servers = 7
pm.max_requests = 500
Also, I never see anything in the php-fpm.log (just NOTICE: configuration file /etc/php5/fpm/php-fpm.conf test is successful)
Anybody?
EDIT:
I have tried running both ondemand and dynamic process manager
I can't leave a comment, although you should check your log file related to php:
( /var/www/ )
( (hostname)/logs/error_log )
and
( /var/log/php5-fpm.log )

How to do port forwarding properly with VirtualBox?

I have a trouble connecting to a guest OS in VirtualBox.
My environtment is as follows:
Host: MacOSX (Lion)
Guest: CentOS (5.7, 2.6.18-274.3.1.el5)
VirtualBox: 4.1.4 r74291
-- Network Adapter Type: NAT
In the guest OS, I can see that the httpd is running properly like:
$ ps aux | grep httpd
root 2571 0.0 3.5 258440 8824 ? Ss 08:20 0:00 /usr/sbin/httpd
apache 2573 0.0 2.2 258440 5780 ? S 08:20 0:00 /usr/sbin/httpd
apache 2574 0.0 2.0 258440 5184 ? S 08:20 0:00 /usr/sbin/httpd
apache 2575 0.0 2.0 258440 5180 ? S 08:20 0:00 /usr/sbin/httpd
apache 2576 0.0 2.0 258440 5180 ? S 08:20 0:00 /usr/sbin/httpd
apache 2577 0.0 2.0 258440 5180 ? S 08:20 0:00 /usr/sbin/httpd
apache 2578 0.0 2.0 258440 5180 ? S 08:20 0:00 /usr/sbin/httpd
apache 2579 0.0 2.0 258440 5180 ? S 08:20 0:00 /usr/sbin/httpd
apache 2580 0.0 2.0 258440 5180 ? S 08:20 0:00 /usr/sbin/httpd
$ curl localhost
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
...
In the host OS, I did a configuration to do port forwarding as follows:
$ VBoxManage showvminfo CentOS_3 | grep "NIC 1"
NIC 1: MAC: 080027B1FA87, Attachment: NAT, Cable connected: on, Trace: off (file: none), Type: Am79C973, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny
NIC 1 Settings: MTU: 0, Socket (send: 64, receive: 64), TCP Window (send:64, receive: 64)
NIC 1 Rule(0): name = http, protocol = tcp, host ip = , host port = 8003, guest ip = , guest port = 80
NIC 1 Rule(1): name = ssh, protocol = tcp, host ip = , host port = 2203, guest ip = , guest port = 22
As this information go, I'm trying to do port forwarding from 8003 to 80 and from 2203 to 22.
In fact, I can make the ssh connection to the guest OS with "ssh -p 2203 localhost".
However, when I try to see http://localhost:8003, the browser says
"Unable to load the webpage because the server sent no data."
When I try "telnet localhost 8003" in the host OS
it seems the port is listening, but there
appears no log in the access log of the guest OS.
What should I do to solve this problem? Thanks in advance!
(addition: Oct. 14 15:55)
$ netstat -nl | grep tcp | grep 127.0.0.1 # Host OS
tcp4 0 0 127.0.0.1.8003 127.0.0.1.64698 ESTABLISHED
tcp4 0 0 127.0.0.1.64698 127.0.0.1.8003 ESTABLISHED
tcp4 0 0 127.0.0.1.26164 127.0.0.1.53917 ESTABLISHED
tcp4 0 0 127.0.0.1.53917 127.0.0.1.26164 ESTABLISHED
tcp4 0 0 127.0.0.1.2203 127.0.0.1.53183 ESTABLISHED
tcp4 0 0 127.0.0.1.53183 127.0.0.1.2203 ESTABLISHED
$ netstat -nl | grep tcp # Guest OS
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:952 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 :::80 :::* LISTEN
tcp 0 0 :::22 :::* LISTEN
tcp 0 0 :::443 :::* LISTEN
It seems that like mkj wrote, you have a firewall installed.
try running (as root):
yum install system-config-firewall-tui
run system-config-firewall-tui, select customize and make sure that "WWW (HTTP)" is checked.
Although old question, but this may be helpful to someone, as I faced this problem today.
As mentioned by mkj, the issue is with Guest OS ( Centos 6 in my case) firewall. It allows ssh (port 22) connection, but blocks others. I had issue accessing postgresql server running in Guest OS (at port 5432) from Host. So executing following iptables command on Guest OS worked:
$ sudo iptables -I INPUT -p tcp -m tcp --dport 5432 -j ACCEPT
In your case, for httpd server running at port 80, you may have to do below:
$ sudo iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT
I never faced this problem when running ubuntu/debian as Guest OS, so probably firewall is not configured in them.

How to detect system power events such as suspend, hibernate, etc

I want to make a Linux application that send a message to a remote host when a local system (where the application runs) is going to suspend, hibernate or shutdown. I googled how to do this and found acpi_listen but it doesn't work.
Here is the result of ps aux | grep acpi on the system I tested (Ubuntu 10.04 LTS):
root 35 0.0 0.0 0 0 ? S Dec03 0:00 [kacpid]
root 36 0.0 0.0 0 0 ? S Dec03 0:00 [kacpi_notify]
root 37 0.0 0.0 0 0 ? S Dec03 0:00 [kacpi_hotplug]
root 934 0.0 0.0 2048 872 ? Ss Dec03 0:00 acpid -c /etc/acpi/events -s /var/run/acpid.socket
Communicating with acpid directly via a UNIX domain socket wouldn't work since that's the way acpi_listen works, although I didn't try it. Is there any other way?
Listen for them over D-Bus.

Resources