Prerequisites: centos7 , the network has been configured
1, install nginx
1.1 , dependent libraries
yum install gcc-c++ yum install -y pcre-devel yum install -y zlib zlib-devel yum install -y openssl openssl-devel
1.2 , downloaded from the official website down nginx-1.14.2.tar.gz installation package via FTP upload to 27 directory / root under
http://nginx.org/en/download.html
1.3 , unzip installation
cd /root tar -zxvf nginx-1.14.2.tar.gz cd nginx-1.14.2 ./configure make make install
1.4 , start
Start nginx
/usr/local/nginx/sbin/nginx
1.5 to detect whether a successful start
ps -ef | grep nginx
1.6 , firewall settings
After installation requires access to 80 ports, the firewall needs to be set
firewall-cmd --permanent --add-port=80/tcp --zone=public firewall-cmd --permanent --add-port=8800/tcp --zone=public firewall-cmd --permanent --add-port=8880/tcp --zone=public firewall-cmd --permanent --add-port=8090/tcp --zone=public
Check the firewall settings have taken effect as well as the command of the firewall in force
cmd---list- Firewall All Firewall -cmd - reload # reload firewall Firewall -cmd --list-All
1.7 , the nginx_new.conf via FTP upload / / usr / local / nginx / conf directory, replacing the original name
cd /usr/local/nginx/conf/
mv nginx.conf nginx_bak.conf
mv n ginx_new.conf nginx.conf
If the new distribution server ip changed, you need to modify nginx configuration file
1.8 , restart nginx entry into force
/ usr / local / nginx / sbin / nginx - S # reload restart
/ usr / local / nginx / sbin / nginx -s stop # Stop
2, set up nginx from Start (startup script by self realization)
2.1 , create a script file
cd /etc/init.d/
came start.sh
Copy the following content into start.sh file
#!/bin/sh #chkconfig:2345 80 90 #decription:auto_run log_path='/usr/local/logs/autoStart.log'; #error information direct to the log exec 2>>$log_path; exec 1>>$log_path; #method for echo message to the log print(){ echo [`date +"%Y-%m-%d %T"`]: $1>>$log_path; } #main /usr/local/nginx/sbin/nginx; print "Start Success " ;
After replacing the file : wq to save and exit
2.2 , since the startup script assigned permissions
chmod +x start.sh
chkconfig --add start.sh
Because log_path directory under /usr/local/logs/autoStart.log There is no need to create
cd /usr/local
mkdir logs
2.3 , is set to confirm the success from the start
After completing the above steps need to restart the server
reboot
Again through the ssh connection 27 server, even after the command to check whether a successful start
ps -ef | grep nginx
Access to the server ip + port verify successful start
192.168.1.27:80 192.168.1.27:8880 192.168.1.27:8800 192.168.1.27:8090