• Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
AnonyViet - English Version
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
No Result
View All Result
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
No Result
View All Result
AnonyViet - English Version
No Result
View All Result

Script to automatically start Nginx, Mariadb, PHP when Web error 502 Bad Gateway

AnonyViet by AnonyViet
January 25, 2023
in Network
0

In some cases where the server crashes, causing the Website to not work, we can use cronjob to check, if the Website returns error code 502 Bad Gateway, then restart nginx, mariadb, php7.4-fpm. Proceed as follows:

Join the channel Telegram of the AnonyViet 👉 Link 👈

Auto Restart Nginx, Mariadb, PHP When Website Error 502 Bad Gateway

Create file 502.sh with content:

#!/bin/bash

CheckURL="https://anonyviet.com"
 
STATUS_CODE=`curl -o /dev/null -m 10 --connect-timeout 10 -s -w %{http_code} $CheckURL`
echo $STATUS_CODE
if [[ "$STATUS_CODE" == '000' || "$STATUS_CODE" == '502' ]]; then

    /usr/bin/systemctl restart nginx
    /usr/bin/systemctl restart mariadb
    /usr/bin/systemctl restart php7.4-fpm
    echo "sap web vao luc: $(date)" >> /root/a.txt
fi

Explain:

  • If curl returns error code 000 or 502 then execute 3 commands restart nginx, mariadb, php7.4-fpm
  • Also record the Log when these 3 services restart to the file a.txt

Timer every minute to run file 502.sh to check

Type command to open cronjob

EDITOR=nano crontab -e

Paste the following into the Terminal window (run the file /root/502.sh . every minute)

* * * * * bash /root/502.sh >/dev/null 2>&1

Press Ctrl+O, Enter to save and Ctrl+X to exit

Tut by An0nyViet

The article achieved: 5/5 – (100 votes)

Tags: AutomaticallyBaderrorGatewayMariadbNginxPHPscriptStartweb
Previous Post

Lesson 248: Gantt chart in Excel

Next Post

Should I use Unity to program games?

AnonyViet

AnonyViet

Related Posts

The website can still be interrupted when the hosting infrastructure is attacked
Network

The website can still be interrupted when the hosting infrastructure is attacked

December 1, 2026
AnonyViet LLM – Summary of 125 Prompt Jailbreak AI, Uncensored
Network

AnonyViet LLM – Summary of 125 Prompt Jailbreak AI, Uncensored

November 29, 2026
TOP 10 AI không kiểm duyệt – AI Uncensored mới nhất
Network

TOP 10 AI không kiểm duyệt – AI Uncensored mới nhất

November 28, 2026
Vietnam static residential proxy: How to choose and use the service
Network

Vietnam static residential proxy: How to choose and use the service

November 26, 2026
SSHWATCH: Dashboard to see realtime VPS attacks using Honeypot
Network

SSHWATCH: Dashboard to see realtime VPS attacks using Honeypot

November 23, 2026
Purple Team: How to verify that the monitoring system can actually detect attacks
Network

Purple Team: How to verify that the monitoring system can actually detect attacks

November 23, 2026
Next Post
Should I use Unity to program games?

Should I use Unity to program games?

0 0 votes
Article Rating
Subscribe
Login
Notify of
guest

guest

0 Comments
Oldest
Newest Most Voted

Recent News

Shortcut to download TikTok videos without logo to replace SnapVideo

Shortcut to download TikTok videos without logo to replace SnapVideo

December 2, 2026
Expense Note

Expense Note

December 2, 2026
Share the latest free IObit Malware Fighter 14 key 2026

Share the latest free IObit Malware Fighter 14 key 2026

December 2, 2026
Instructions on how to turn text into songs on Messenger

Instructions on how to turn text into songs on Messenger

December 1, 2026
Shortcut to download TikTok videos without logo to replace SnapVideo

Shortcut to download TikTok videos without logo to replace SnapVideo

December 2, 2026
Expense Note

Expense Note

December 2, 2026
Share the latest free IObit Malware Fighter 14 key 2026

Share the latest free IObit Malware Fighter 14 key 2026

December 2, 2026
AnonyViet - English Version

AnonyViet

AnonyViet is a website share knowledge that you have never learned in school!

We are ready to welcome your comments, as well as your articles sent to AnonyViet.

Follow Us

Contact:

Email: anonyviet.com[@]gmail.com

Main Website: https://anonyviet.com

Recent News

Shortcut to download TikTok videos without logo to replace SnapVideo

Shortcut to download TikTok videos without logo to replace SnapVideo

December 2, 2026
Expense Note

Expense Note

December 2, 2026
  • Home
  • Home 2
  • Home 3
  • Home 4
  • Home 5
  • Home 6
  • Next Dest Page
  • Sample Page

say88 tỷ lệ kèo nhà cái kèo nhà cái 5 febet

No Result
View All Result
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office

say88 tỷ lệ kèo nhà cái kèo nhà cái 5 febet

wpDiscuz
0
0
Would love your thoughts, please comment.x
()
x
| Reply