Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to Nginx the server and configure the startup script

Shulou Source: shulou.com Published: 2022-06-02 05:09:01 09月15日 Update

This article mainly explains "how to configure Nginx server and startup script". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the idea of Xiaobian slowly and deeply to study and learn "how to configure Nginx server and startup script" together!

Experimental environment: RHEL7.2 x64-176, IP address: 192.168.1.176

Experimental tools:

Experimental procedure:

1, Install nginx server

2. Configure nginx startup script

3. File setup and verification results

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

1, Install nginx server

[root@localhost~]# useradd nginx -s /sbin/nologin -M #Create nginx user

[root@localhost~]# id nginx #Verify

uid=1001(nginx)gid=1001(nginx) group =1001(nginx)

[root@localhost ~]# yum install pcre pcre-devel openssl openssl-devel -y #install dependency packages

[root@localhost ~]# tar xf nginx-1.9.14.tar.gz #extract nginx source package to current directory

[root@localhost ~]# cd nginx-1.9.14/ #Enter the decompressed nginx directory

[root@localhost nginx-1.9.14]# ./ configure --user=nginx --group=nginx #Configure nginx

[root@localhostnginx-1.9.14]#make && make install #compile install nginx

[root# /usr/local/nginx/sbin/nginx -t #Check syntax

[root@localhostnginx-1.9.14]# /usr/local/nginx/sbin/nginx

#Access virtual machine IP address test nignx success

2. Configure nginx startup script

[root@localhost~]# vim nginx

==============================================================

#! /bin/bash

# chkconfig:2345 99 20

#description:nginx-server

nginx=/usr/local/nginx/sbin/nginx

case $1 in

start)

netstat -anlpt | grep nginx

if [ $? -eq 0 ]

then

echo "nginx-server isalready running"

else

echo "nginx-server beginstart"

$nginx

fi

;;

stop)

$nginx -s stop

if [ $? -eq 0 ]

then

echo "nginx-server isstoped"

else

echo "nginx-server stopfail,try again"

fi

;;

status)

netstat -anlpt | grep nginx

if [ $? -eq 0 ]

then

echo "nginx-server isrunning"

else

echo "nginx-server isstoped"

fi

;;

restart)

$nginx -s reload &>/dev/null

if [ $? -eq 0 ]

then

echo "nginx-server isbegin restart"

else

echo "nginx-server restartfail"

fi

;;

*)

echo "please enter {startrestart status stop}"

;;

esac

exit 0

================================================================

3. File setup and verification results

[root@localhost~]# cp nginx /etc/init.d/ #Copy boot files to/etc/init.d directory

[root# chmod +x /etc/init.d/nginx #Set executable permissions

[root@localhost ~]# chkconfig --add nginx #add nginx as a service for the system

[root@localhost ~]# chkconfig --list nginx #View nginx startup runlevel

Thank you for reading, the above is the content of "how to configure Nginx server and startup script", after learning this article, I believe everyone has a deeper understanding of how to configure Nginx server and startup script, and the specific use situation needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

Tags: Services configuration servers scripts validation files directories learning labs content addresses results success that is tools ideas situations articles more permissions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft vpn Apple Xiaomi Shulou Information