How to change VestaCP port and add firewall rules 1
VestaCP

How to change VestaCP port and add firewall rules

Here is a simple all in one command solution that will do it for you from terminal

sed -i 's/8083;/2083;/' /usr/local/vesta/nginx/conf/nginx.conf && v-add-firewall-rule ACCEPT 0.0.0.0/0 2083 TCP && v-delete-firewall-rule 2 && service vesta restart

If you have not modified the default firewall rules #2 is for the 8083. If you have you can use this longer command to be more safe

sed -i 's/8083;/2083;/' /usr/local/vesta/nginx/conf/nginx.conf && v-add-firewall-rule ACCEPT 0.0.0.0/0 2083 TCP && sed -i -e '/8083/ s/ACCEPT/DROP/' /usr/local/vesta/data/firewall/rules.conf && v-update-firewall && service vesta restart

Breakdown of the command

The parts of the first example are as follows so that you can see whats getting done and one command at a time.

Changes the port in the nginx file

sed -i 's/8083;/2083;/' /usr/local/vesta/nginx/conf/nginx.conf

Add firewall rule for new port using VestaCP command

/usr/local/vesta/bin/v-add-firewall-rule ACCEPT 0.0.0.0/0 2083 TCP

Remove old port firewall rule using VestaCP command

/usr/local/vesta/bin/v-delete-firewall-rule 2

Restart VestaCP

service vesta restart

Or

curl http://www.nodehost.ca/scripts/sh/vestacp_changeport.sh > vestacp_changeport.sh && bash vestacp_changeport.sh

Feel free to download and see what the file actually does, and if you want to upload a file and run local here is the script in the file.

echo "NodeHost Custom VESTACP Script"

echo "JOB: Changing VESTACP port"
string="listen          8083;"
stringnew="listen          5600;"
grep "$stringnew" /usr/local/vesta/nginx/conf/nginx.conf || sed -i "s/$string/$stringnew/g" /usr/local/vesta/nginx/conf/nginx.conf
echo "JOB: Complete"

echo "JOB: Changing VESTACP firewall rule for new port"
v-add-firewall-rule ACCEPT 0.0.0.0/0 5600 TCP
echo "JOB: Complete"

echo "JOB: Restarting VESTACP"
service vesta restart
echo "JOB: Complete"

echo "JOB: Port has been changed to 5600 from 8083"

 

Avatar of Bình Minh

Tui là Nguyễn Xuân Bình Minh

Để lại một bình luận

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *

Website này sử dụng Akismet để hạn chế spam. Tìm hiểu bình luận của bạn được duyệt như thế nào.