Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Building Nginx website Service in Linux system

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

About Nginx

A high-performance, lightweight Web service software

High stability

Low system resource consumption

High processing capacity for HTTP concurrent connections

A single physical server can support 30000 to 50000 concurrent requests

Nginx compilation installation Nginx source code package download installation support software [root@localhost opt] yum install gcc gcc-c++ make pcre-devel zlib-devel-y create and run user, Group [root@localhost opt] useradd-M-s / sbin/nologin nginx compile and install Nginx [root @ localhost ~] mount.cifs / / 192.168.100.10/lnmp / mnt/ Mount the local nginx source package to the mnt directory [root@localhost ~] cd / mnt/ [root@localhost mnt] tar zxvf nginx-1.12.2.tar.gz-C / opt/ decompress the source package to the opt directory [root@localhost mnt] cd / opt [root@localhost opt] cd nginx-1.12.2/ enter the nginx installation package directory [root@localhost nginx-1.12.2]. / configure\-- prefix=/usr/local/nginx\ / / specify installation path-- user=nginx\ / / specify program user-- group=nginx\ / / specify group-- with-http _ stub_status_module / / associated status statistics module [root@localhost nginx-1.12.2] make & & make install / / configuration, Install [root@localhost nginx-1.12.2] cd / usr/local/nginx/sbin/ / enter the command directory after nginx installation [root@localhost sbin] ln-s / usr/local/nginx/sbin/nginx / usr/local/sbin/ establish a soft link to the sbin directory [root@localhost sbin] nginx/ / perform open service [root@localhost conf] # netstat-ntap | grep 80 / / View the service port Whether to enable tcp 0 0 0.0.0 master 80 0.0.0 master * LISTEN 31755/nginx: master [root@localhost sbin] systemctl stop firewalld.service / / turn off firewall [root@localhost sbin] setenforce 0 / / turn off enhanced security [root@localhost sbin] yum install elinks-y / / install the detection website tool [root@localhost sbin] elinks http://localhost / / check whether the website is open

Optimized operation control [root@localhost sbin] # vim / etc/init.d/nginx / / Edit run control script #! / bin/bash# chkconfig:-99 2 runs description: Nginx Service Control ScriptPROG= "/ usr/local/nginx/sbin/nginx" PIDF= "/ usr/local/nginx/logs/nginx.pid" case "$1" in start) $PROG;; stop) kill-s QUIT $(cat $PIDF); restart) $0 stop $0 start Reload) kill-s HUP $(cat $PIDF) *) echo "Usage: $0 {start | stop | restart | reload}" exit 1esacexit 0:wq [root@localhost sbin] # cd / etc/init.d [root@localhost init.d] # chmod + x nginx / / add execution permissions to the script [root@localhost init.d] # chkconfig-- add nginx / / add the script to the system environment [root@localhost init.d] # service nginx start / / Open profile global configuration using service control service # user nobody Worker processes 1 is configuring error _ log logs/error.log;#pid logs/nginx.pid;I/0 event configuration events {use epoll; worker_connections 4096;} HTTP configuration http {. Access_log logs/access.log main; sendfile on;. Keepalive_timeout 65; server {listen 80; server name www.bt.com; charset utf-8; location / {root html; index index.html index.php;} error_page 500 502 503 504 / 50x.html; location = / 50x.html {root html Nginx access status statistics enabled HTTP STUB STATUS status statistics module added when configuring compilation parameters-- with-http_ stub_ status_ modulenginx-V check whether the installed Nginx contains the HTTP_ STUB_ _ STATUS module [root@localhost init.d] # cd / usr/local/nginx/conf/ enter the configuration file directory [root@localhost conf] # vim nginx.conf / / to edit the configuration text Piece. / / omit part of the content. Server {listen 80 Server_name www.kgc.com; / / Edit domain name charset utf-8; / / Edit string format is utf-8 # access_log logs/host.access.log; / / comment access log file location / {root html; index index.html index.htm } location / status {stub_status on; / / enable function statistics module access_log off }. / / omit part.: wq / / Save exit [root@localhost conf] # yum install bind-y / / install DNS service [root@localhost conf] # vim / etc/named.conf / / General configuration DNS function. / / omit part of the content. Options {listen-on port 53 {any;} Listen-on-v6 port 53 {:: 1;}; directory "/ var/named"; dump-file "/ var/named/data/cache_dump.db"; statistics-file "/ var/named/data/named_stats.txt"; memstatistics-file "/ var/named/data/named_mem_stats.txt"; recursing-file "/ var/named/data/named.recursing" Secroots-file "/ var/named/data/named.secroots"; allow-query {any;};. / / omit part...: wq [root@localhost conf] # vim / etc/named.rfc1912.zones...// omit part... zone "kgc.com" IN {type master; file "kgc.com.zone"; allow-update {none;};} ...: wq [root@localhost conf] # cd / var/named/ [root@localhost named] # cp-p named.localhost kgc.com.zone [root@localhost named] # vim kgc.com.zone$TTL 1D @ IN SOA @ rname.invalid. (0; serial 1D; refresh 1H; retry 1W; expire 3H) Minimum NS @ A 127.0.0.1www IN A 192.168.144.133:wq [root@localhost named] # systemctl start named [root@localhost named] # service nginx stop [root@localhost named] # service nginx start opens a browser in the client to enter the domain name www.kgc.com/status to access the website statistics record

The authorized access control configuration steps are basically the same as Apache. Generate the user password authentication file, modify the main configuration file to the corresponding directory, add authentication configuration items to restart the service, access test [root@localhost ~] # vim / usr/local/nginx/conf/nginx.confserver {listen 80; server_name www.kgc.com; charset utf-8; # access_log logs/host.access.log Location / {auth_basic "secret"; / / insert set password verification auth_basic_user_file / usr/local/nginx/passwd.db; / / add entry set password verification file storage directory root html; index index.html index.htm } location / status {stub_status on; access_log off }: wq [root@localhost ~] # yum install httpd-tools-y / / installation generation password settings file loaded plug-in: fastestmirror Langpacksbase | 3.6 kB 00:00:00 extras | 2.9 kB 00:00:00. / / omit part of the content. Installed: httpd-tools.x86_64 05.el7 apr-util.x86_64 2.4.6-90.el7.centos is installed as a dependency: apr.x86_64 0VOR 1.4.8-5.el7 apr-util.x86_64 0VR 1.5.2-6.el7 is over! [root@localhost ~] # htpasswd-c / usr/local/nginx/passwd.db test01 / / create password authentication file New password: / / enter password Re-type new password: / / re-enter Adding password for user test01 / / create user successfully [root@localhost ~] # cat / usr/local/nginx/passwd.db / / View the created password file test01:$apr1 $T22NmXdU$yE8iwUxpaHcR95ZNosCUK0 / / user password information [root@localhost ~] # service nginx stop / / stop the nginx service [root@localhost ~] # service nginx start / / start the nginx service [root@localhost ~] # netstat-ntap | grep 80 / / check whether the port opens tcp 000.0.0.0800 0 .0.0.0: * LISTEN 8624/nginx: test authorized access control in the client

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report