How to quickly build Nginx server under CentOS

View server version

# cat /etc/redhat-release
CentOS Linux release 8.1.1911(Core)

installation steps

  1. Update yum
# yum updateFailed to set locale, defaulting to C.UTF-8CentOS-8- AppStream                                                                                                                                              4.1 kB/s |4.3 kB     00:01CentOS-8- Base                                                                                                                                                   5.1 kB/s |3.8 kB     00:00CentOS-8- Extras                                                                                                                                                 4.1 kB/s |3.0 kB     00:00Dependencies resolved.Nothing to do.Complete!
  1. Install Nginx
sudo yum install nginx
  1. Configure Nginx

Set boot up

# sudo systemctl enable nginx

Start service

# sudo systemctl start nginx

Out of service

# sudo systemctl restart nginx

Reload

# sudo systemctl reload nginx

Firewall configuration

# sudo firewall-cmd --zone=public--permanent --add-service=httpsuccess

Open a port and reload the configuration to take effect. lasting

# sudo firewall-cmd --add-port=80/tcp --permanentsuccess# sudo firewall-cmd --add-port=443/tcp --permanentsuccess

Restart the server and check the firewall status.

# sudo firewall-cmd --list-servicedhcpv6-client http ssh

Query release port

# sudo firewall-cmd --list-ports80/tcp

Nginx common mistakes

View error message

# cat /var/log/nginx/error.log
  1. Modify nginx.conf to start the user
# ps aux | grep "nginx: worker process"| awk '{print $1}'nobodyroot
# vim conf/nginx.confuser root;worker_processes auto;error_log /var/log/nginx/error.log;...
  1. Modify html file permissions

View the file permissions of the original html directory

# ls -lrtZ /usr/share/nginx/htmltotal 24-rw-r--r--.1 root root system_u:object_r:httpd_sys_content_t:s0  368 Oct  721:16 nginx-logo.png-rw-r--r--.1 root root system_u:object_r:httpd_sys_content_t:s0 4057 Oct  721:16 index.html-rw-r--r--.1 root root system_u:object_r:httpd_sys_content_t:s0 4020 Oct  721:16 50x.html-rw-r--r--.1 root root system_u:object_r:httpd_sys_content_t:s0 3971 Oct  721:16404.html-rw-r--r--.1 root root system_u:object_r:httpd_sys_content_t:s0 4148 Oct  721:16 poweredby.png

Modify custom catalog

chcon -R -u system_u /xxx/chcon -R -t httpd_sys_content_t /xxx/

Security configuration

  1. Hide directory
http {  autoindex off;}
  1. Hide show version number
http {  server_tokens off;}
  1. Restrict access to request parameters
http {  #Set client request header read timeout client_header_timeout 15;  #Set the client request body read timeout client_body_timeout 15;     #Upload file size limit client_max_body_size 10m;  #Specify the timeout period to respond to the client send_timeout    60;  #Set the timeout period keepalive for the client connection to keep the session_timeout 60;}
  1. Access restrictions, allow is the ip and ip segments that are allowed to be accessed, deny is the ip and ip segments that are forbidden to access
# Set the access permission of the website root directory location/{    allow 192.168.1.1/24;    deny 192.168.1.2/24;    deny all;}
  1. Restrict access to individual directories or file extensions
# When visiting uploads, p_w_Picpaths directory specifies the file location of the suffix~^/(uploads|p_w_picpaths)/.*\.(php|php5|jsp)$ {return403;}#Prohibit access to files with specified suffixes in all directories~.*\.(sql|log|txt|jar|war|sh|py){    deny all;}

Recommended Posts

How to quickly build Nginx server under CentOS
How to quickly modify root password under CentOS8
Build OpenV** Server under CentOS7
Build OpenLDAP server under CentOS7
CentOS uses Nginx to build a download function server
How to open https on nginx server under Ubuntu
How to install Nginx on CentOS 8
Build an FTP server under centos7
How to monitor CentOS 7 server with Prometheus
How to set up the Nginx server configuration block on CentOS 8
How to change the CentOS server time to Beijing time
How to quickly deploy docker on ubuntu server
Centos7 tutorial to build a master-slave DNS server
How to modify the CentOS server time to Beijing time
How to build a LAMP environment on centos7.2
3 minutes to teach you to build gitea on Centos server
Use Rancher to build a K8s cluster under CentOS7
How to configure FTP server with Vsftpd on CentOS 8
Centos8 implementation steps to build a local web server
How to install and configure NFS server on CentOS 8
How to quickly install docker on Linux (Centos version)
How to configure FTP server with Vsftpd on CentOS 8
How to use Let's Encrypt to protect Nginx on CentOS 8
How to learn python quickly
Install Nginx server on CentOS 7
How to install and configure Postfix mail server on CentOS8
Teach you how to build a Git server on Ubuntu
How to build an NFS file sharing server on Ubuntu 16.04
How to install MySQL on CentOS 8
How to upgrade CentOS7 to CentOS8 (detailed steps)
How to install Memcached on CentOS 8
Use Nginx and u under CentOS
How to install R on CentOS 8
How to install FFmpeg on CentOS 8
How to install Virtualbox on CentOS 8
How to install TensorFlow on CentOS 8
[Introduction to redis] Install redis under Centos
How to Update to gcc4.9.x on Centos7
How to install TeamViewer on CentOS 8
CentOS8.1 build Gitlab server detailed tutorial
How to install Perl 5 on CentOS
How to install Git on CentOS 8
How to install PHP7.4 in CentOS
How to install Gradle on CentOS 8
How to install Elasticsearch on CentOS 8
How to install Jenkins on CentOS 8
How to install Java on CentOS 8
How to install Go on CentOS 8
Build a PXC cluster under CentOS8
How to compile ijkplayer-android under ubuntu
How to install GCC on CentOS 8
How to install Yarn on CentOS 8
How to install Asterisk on CentOS 7
How to install Jenkins on CentOS 8
How to install Vagrant on CentOS 8
How to install Python 3.8 on CentOS 8
How to install Tomcat 9 on CentOS 8
How to install Webmin on CentOS 8
Centos6 method steps to build gitlab
How to install Ruby on CentOS 8
How to install Skype on CentOS 8