Symfony2 with Ngix Bad gateway on hold f5 - mysql

When I pressed f5 button in my webpage (5~ seconds kept, test purpose)
my website displays
"502 bad gateway"
I am using symfony 2.6 and mysql with PHP-fpm my VPS have 1GB RAM and 1 core CPU. the nginx log display:
2015/05/12 12:41:17 [error] 9541#0: *661 connect() to unix:/var/run/php5-fpm.sock failed (11: Resource temporarily unavailable)
while connecting to upstream,
client: 127.0.0.1,
server: localhost,
request: "GET /app_dev.php/ HTTP/1.1",
upstream: "fastcgi://unix:/var/run/php5-fpm.sock:",
host: "localhost"
The connection is lost after the test and return after 30 seconds~
Question: How can I configure Nginx to prevent that? I need that my website don't fall on many http request

Related

Elastic Beanstalk amazon linux 2 and Nginx "/var/www/html/webroot" existence failed 2"

I got this error from Nginx after deploying the code to AWS EB. The weird thing it is that I can access by ssh to the EC2 instance and the folder and file both EXISTS /var/www/html/webroot/index.php
2022/11/01 15:45:10 [error] 1456#1456: *36 testing "/var/www/html/webroot" existence failed (2: No such file or directory) while logging request, client: 0x2.21.03.15, server: , request: "GET / HTTP/1.1", host: "0x2.21.03.1"
2022/11/01 15:45:20 [error] 1456#1456: *37 "/var/www/html/webroot/index.php" is not found (2: No such file or directory), client: 0x2.21.03.1, server: , request: "GET / HTTP/1.1", host: "0x2.21.03.1"
UPDATE: I fixed the other error by removing a bespoke Nginx.conf file I was pushing with each deployment, but now I am getting this error:
2022/11/01 12:42:28 [error] 13146#13146: *25 open() "/var/www/html/webroot/.git/config" failed (2: No such file or directory), client: 142.xx.xx.1, server: , request: "GET /.git/config HTTP/1.1", host: "3.xx.xx3.x5"
I do not understand why and where EB is checking for a /.git/config file. I have the same code in a different instance type (t3.micro) and it works fine. I never had these issues before, it starts happening when I created a new environment with an instance type "t4g.micro"
Any ideas?
note: Both environments works with Amazon Linux 2 and Nginx server.

AWS Elastic Beanstalk Notification - Environment health has transitioned from Ok to Warning

I keep getting the following messages. But there is nothing in my nginx logs which indicates that requests were returned with status 5xx. Also, app seems to working as expected. Any pointers why I might be getting these?
Message:
Environment health has transitioned from Ok to Warning. 50.0 % of the requests are failing with HTTP 5xx. Insufficient request rate (12.0 requests/min) to determine application health. 1 out of 2 instances are impacted. See instance health for details.
eb logs show the following events around the same time. And they look like a hack attempt. My guess is that these POST requests failure are making EB think that instances are unhealthy. Any advise, how can we prevent this ? Thanks.
2019/02/10 23:49:37 [error] 3263#0: *23308 upstream prematurely closed connection while reading response header from upstream, client: 172.31.35.221, server: , request: "POST /51314.php HTTP/1.1", upstream: "http://172.17.0.2:80/51314.php", host: "xxx.xxx.xxx.xxx"
2019/02/10 23:49:37 [error] 3263#0: *23308 upstream prematurely closed connection while reading response header from upstream, client: 172.31.35.221, server: , request: "POST /fusheng.php HTTP/1.1", upstream: "http://172.17.0.2:80/fusheng.php", host: "xxx.xxx.xxx.xxx"
2019/02/10 23:49:38 [error] 3263#0: *23308 upstream prematurely closed connection while reading response header from upstream, client: 172.31.35.221, server: , request: "POST /repeat.php HTTP/1.1", upstream: "http://172.17.0.2:80/repeat.php", host: "xxx.xxx.xxx.xxx"
2019/02/10 23:49:39 [error] 3263#0: *23308 upstream prematurely closed connection while reading response header from upstream, client: 172.31.35.221, server: , request: "POST /api.php HTTP/1.1", upstream: "http://172.17.0.2:80/api.php", host: "xxx.xxx.xxx.xxx"
2019/02/10 23:49:40 [error] 3263#0: *23308 upstream prematurely closed connection while reading response header from upstream, client: 172.31.35.221, server: , request: "POST /xiaodai.php HTTP/1.1", upstream: "http://172.17.0.2:80/xiaodai.php", host: "xxx.xxx.xxx.xxx"
2019/02/10 23:49:40 [error] 3263#0: *23308 upstream prematurely closed connection while reading response header from upstream, client: 172.31.35.221, server: , request: "POST /xiaodai.php HTTP/1.1", upstream: "http://172.17.0.2:80/xiaodai.php", host: "xxx.xxx.xxx.xxx"
Thanks.
Example reasons can be
nginx proxy crashed on the instance
high CPU usage on the instance
high memory usage on the instance
deployment failure on the instance

NGINX crashes with 404 not found error

I have ubuntu 14.04 and on the server I have nginx & mysql.
Everything works fine but after 5-10 requests to the API the nginx crashes.
The site has been loading for a long time ends up with 404 not found error.
When I restart the service service nginx restart my site is up again.
I have a strong server with
64GB Ram, 1Gbit Port 33TBMonth,
1TB Disk. 12Cores 24Threads.
I don't understand what's the error and how to solve it.
This is the nginx.conf:
https://pastebin.com/raw/eQtMSKAY
error log nginx:
2017/07/30 06:55:43 [error] 18441#0: *6302 connect()
to unix:/var/run/php5-fpm.sock failed (11: Resource
temporarily unavailable) while connecting to upstream,
client: XX.XX.XX.XX, server: 4107.150.4.82, request:
"GET /panel/ajax/user/tools/server?method=getstatus&port=25565 HTTP/1.1",
upstream: "fastcgi://unix:/var/run/php5-fpm.sock:",
host: "pay2play.co.il", referrer:
"http://pay2play.co.il/panel/panel?id=15"
2017/07/30 06:55:43 [error] 18441#0: *6302 open()
"/usr/share/nginx/html/50x.html" failed (2: No such file
or directory), client: 5.29.8.30, server: 107.150.44.82,
request: "GET /panel/ajax/user/tools/server?method=getstatus&port=25565 HTTP/1.1",
upstream: "fastcgi://unix:/var/run/php5-fpm.sock",
host: "pay2play.co.il", referrer:
"http://pay2play.co.il/panel/panel?id=15"
Based on what you pasted, the actual error is on the PHP side. The 404 is just nginx attempting to render a "nice" error page for the 503/4, contained in 50x.html. While your pasted version doesn't include it, it's likely contained in one of the includes (which are more relevant to the question than the top-level configuration shown here).
I expect there is something like (from the nginx docs actually):
error_page 500 502 503 504 /50x.html;

Zabbix JMX Tomcat monitoring

I have been trying to setup Zabbix to monitor my 2 tomcat servers on 2 different Amazon EC2 machines, but in vain.
The Z on the host is green, however te JMX is red with these errors
- ZBX_TCP_READ() failed: [4] Interrupted system call
- Someother error [111] connection refused
and many such errors, one after another, in the sense I resolve an error to see one more new error popping up.
These are some assumptions
All the machines run Ubuntu 12.10 and later
Server's IP address: 66.55.12.120 (Runs Zabbix server v2.2.4 (revision 46772) (23 June 2014) )
Agent's IP address: 87.52.45.198 ( Runs Zabbix agent v2.2.2 (revision 42525) (12 February 2014) )
My local machine's IP address: 76.89.54.111
Here is what I've done so far.
On Server Side:
1) Installed Zabbix_server using sudo apt-get install zabbix-server-mysql.
2) The GUI, mysql database all have been installed and configured.
3) The following are the only 3 changes that I've made in the file /etc/zabbix/zabbix_server.conf
...
JavaGateway=localhost
JavaGatewayPort=10052
StartJavaPollers=5
...
4) The Zabbix Java gateway was installed using sudo apt-get install zabbix-java-gateway.
5) The following are the only 3 changes that I've made in the file
/etc/zabbix/zabbix_java_gateway.conf
...
LISTEN_IP="127.0.0.1"
LISTEN_PORT=10052
START_POLLERS=5
...
On Client Side:
1) Installed Zabbix Client using
sudo apt-get install zabbix-agent
2) The following are the only 3 changes that I've made in the file
/etc/zabbix/zabbix_agentd.conf
...
Server=66.55.12.120
StartAgents=5
ServerActive=66.55.12.120:10051
Hostname=Security-test-JMX-EC2
... <br />
3) The Hostname is the same as the one that is mentioned while creating the Host on the GUI.
I believe that there are some issues with the IP and ports. So, here are the outbound rules for both the machines as obtained from Amazon EC2 Security Groups for the machines
OUTBOUND RULES for SERVER SECURITY GROUP:
Type Protocol Port Source Reasoning
Custom- TCP 8080 0.0.0.0/0
TCP Rule
All ICMP All N/A 0.0.0.0/0
Custom- TCP 10052 27.52.52.128/32 For access from Agent
TCP Rule
Custom- TCP 8081 76.84.120.130/32 To access Zabbix GUI from-
TCP Rule -my local machine's web browser
Custom- TCP 10051 27.52.52.128/32 As the agent responds to-
TCP Rule -the server on Port 10051TCP Rule-
-Must allow inbound communications-
- from the agent.
Custom- TCP 11000 27.52.52.128/32 The agent's JMX reporting-
TCP Rule -happens on port 11000(not on 12345).
OUTBOUND RULES for CLIENT SECURITY GROUP:
Type Protocol Port Source
HTTPS TCP 443 0.0.0.0/0
Custom- TCP 10050 66.55.12.120/32
TCP Rule
Custom- TCP 10052 66.55.12.120/32
TCP Rule
Custom- TCP 11000 66.55.12.120/32
TCP Rule
HTTP TCP 80 76.89.54.111/32
Custom- TCP 8080 76.89.54.111/32
TCP Rule
Custom- TCP 8443 76.89.54.111/32
TCP Rule
What am I missing? Please guide me.
Any help is appreciated.
Thanks
Goutham
If you can, then run VisualVm (probably using a tunneled X session) on the zabbix host, and see if you can connect to the target JVM with that. If you can't connect from that, you won't be able to connect from Zabbix.
Try with the following CATALINA_OPTS, replacing with the IP on the target that you want JMX to listen on:
export CATALINA_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9010 -Dcom.sun.management.jmxremote.local.only=falseom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=<LOCAL_IP>"
This will disable all JMX security so be aware!
Once you hopefully get it to connect, the "Tomcat JMX" items in Zabbix are also all incorrect! e.g.
Incorrect Zabbix default:
jmx["Catalina:type=GlobalRequestProcessor,name=http-8080",bytesReceived]
Correct entry:
jmx["Catalina:type=ThreadPool,name=\"http-bio-8080\"", bytesReceived]
Note the escaped quotes and incorrect thread name. Add the Mbeans plugin to VisualVM, and use that to browse the MBeans on the target VM, and check the Zabbix names.
It does work eventually, but is a real pain to setup. Zabbix is however one of the few open source monitoring tools that supports JMX at all!
By default, JMX does not work very well with firewalls. You might find related bug reports on Zabbix tracker useful: ZBX-5326 and ZBX-6815. The first one contains a workaround for Tomcat which might work for you.
#gvatreya wrote:
Server: (Runs Zabbix server)
Agent: (Runs Zabbix agent)
It looks like you have to start Zabbix Java gateway as well on host where it is installed (it is a daemon/service).
I configured as follows:
Server: (Runs Zabbix server, Zabbix Java gateway)
Agent: (Runs Zabbix agent)
I think it is possible to install it on a dedicated host.
Have you tried adding -Djava.net.preferIPv4Stack=true to the VM options?
to make it work add next java_opts to your tomcat startup script
-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.port=2345
-Dcom.sun.management.jmxremote.rmi.port=12345
-Djava.rmi.server.hostname=<tomcat_hostname>

502 bad gateway error

When I browse the Magento web site multiple times, I usually get 502 bad gateway error at Nginx.
Please help me on fixing this issue.
Note:- php5-fpm is not running some of the time. After restarting the php5-fpm, everything is working fine but after some time I am getting the same(php5-fpm is not running) error again .
Ngnix Error Logs: -
2014/06/30 12:24:17 [error] 13359#0: *297122 connect() failed (111: Connection refused) while connecting to upstream, client: xxxxxxxx, server: www.xxxxxxxx.com, request: "GET /ultimate-comics-x-men-1967641 HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.xxxxxxxx.com"
2014/06/30 12:24:28 [error] 13359#0: *297124 connect() failed (111: Connection refused) while connecting to upstream, client: xxxxxxxx, server: www.xxxxxxxx.com, request: "GET /virtual-engineering-simulation-and-optimization HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.xxxxxxxx.com"