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

Nginx website service-service foundation, access control (actual combat! )

2025-01-18 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 request environments, a Linux server (192.168.13.128), a win10 test machine, and one win10 test machine to share the compression packages needed by LAMP on Windows (if you have any questions here, please see the previous blog article)

two, Use remote sharing on Linux to obtain files and mount them to the mnt directory [root@localhost] # smbclient-L / / 192.168.100.3 / # # remote share access Enter SAMBA\ root's password: Sharename Type Comment-LAMP- C7 Disk [root@localhost ~] # mount.cifs / / 192.168.100.3/LAMP-C7 / mnt # # Mount to / mnt directory Compile and install Nginx1, decompress the source code package to / opt And check [root@localhost ~] # cd / mnt # # switch to the mount point directory [root@localhost mnt] # lsapr-1.6.2.tar.gz Discuz_X2.5_SC_UTF8.zip LAMP-php5.6.txtapr-util-1.6.0.tar.gz error.png mysql-5.6.26.tar.gzawstats-7.6.tar.gz Httpd-2.4.29.tar.bz2 nginx-1.12.0.tar.gzcronolog-1.6.2-14.el7.x86_64.rpm kali.jpg php-5.6.11.tar.bz2 [root@localhost mnt] # tar zxvf nginx-1.12.0.tar.gz-C / opt # # decompress the Nginx source package to [root@localhost mnt] # cd / opt/ # # switch to [root@localhost opt] # lsnginx-1.12.0 rh2 under the unzipped directory Install the environment component package required for compilation [root@localhost opt] # yum-y install\ gcc\ / c language gcc-c++\ / / C++ language pcre-devel\ / / pcre language tool zlib-devel / / function library for data compression 3 Create program user nginx and compile Nginx [root@localhost opt] # useradd-M-s / sbin/nologin nginx # # create program user Security non-login status [root@localhost opt] # id nginxuid=1001 (nginx) gid=1001 (nginx) group = 1001 (nginx) [root@localhost opt] # cd nginx-1.12.0/ # # switch to the nginx directory [root@localhost nginx-1.12.0]. / configure\ # # configure nginx >-- prefix=/usr/local/nginx\ # # installation path >-- user=nginx\ # # user name >-- group=nginx\ # # user group >-- with-http_stub_status_module # # status statistics module 4 Compile and install [root@localhost nginx-1.12.0] # make # # compile... [root@localhost nginx-1.12.0] # make install # # install .5, optimize the nginx startup script So that the system can recognize [root@localhost nginx] # ln-s / usr/local/nginx/sbin/nginx / usr/local/sbin/ # # create a soft connection to let the system recognize the nginx startup script [root@localhost nginx] # nginx-t # # check the syntax problems of the configuration file nginx: the configuration file / usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file / usr/local/nginx/conf/nginx.conf test is successful [root@localhost Nginx] # nginx # # Open ngnix [root@localhost nginx] # netstat-ntap | grep 80 # # View port Nginx has enabled tcp 0 0 0.0.0 LISTEN 39620/nginx: master [root@localhost nginx] # systemctl stop firewalld.service # # turn off the firewall [root@localhost nginx] # setenforce 0 6 and install the elinks web page testing tool And test [root@localhost nginx] # yum install elinks-y # # install elinks software [root@localhost nginx] # elinks http://localhost # # Test nginx web page

7. Enable reloading and disable [root@localhost nginx] # killall-s QUIT nginx # # stop or restart using killall-3 nginx [root@localhost nginx] # killall-s HUP nginx # # or turn on 8 using killall-1 nginx [root@localhost nginx] # nginx # # to create a management script Easy to use service management to use [root@localhost nginx] # cd / etc/init.d/ # # to switch to the startup configuration file directory [root@localhost init.d] # lsfunctions netconsole network README [root@localhost init.d] # vim nginx # # Edit the startup script file #! / bin/bash# chkconfig:-99 20 # # comment Information # description: Nginx Service Control ScriptPROG= "/ usr/local/nginx/sbin/nginx" # # set the variable to the nginx command file PIDF= "/ usr/local/nginx/logs/nginx.pid" # # set the variable PID file process number is 5346case "$1" in start) $PROG # # start the service ; stop) kill-s QUIT $(cat $PIDF) # # disable the service;; restart) # # restart the service $0 stop $0 start Reload) # # reload service kill-s HUP $(cat $PIDF) *) # # incorrect input prompt echo "Usage: $0 {start | stop | restart | reload}" exit 1esacexit 0 [root@localhost init.d] # chmod + x / etc/init.d/nginx # # give startup script execution permission [root@localhost init.d] # chkconfig-- add nginx # # add to service Manager [root@localhost init.d] # service nginx stop # # you can use service to control the access status statistics of nginx [root@localhost init.d] # service nginx startNginx to enable HTTP_STUB_STATUS status statistics module nginx-V to check whether the installed Nginx contains statistics module one Modify nginx configuration file [root@localhost ~] # cd / usr/local/nginx/conf # # change to configuration file directory [root@localhost conf] # vim nginx.conf # # modify Nginx configuration file server {listen 80 Server_name www.kgc.com; # # specifies a domain name charset utf-8; # # Chinese character set # access_log logs/host.access.log main; location / {root html; index index.html index.htm } location / status {# # add status Statistics stub_status on; access_log off Second, install DNS server for domain name resolution 1, install bind service [root@localhost conf] # yum install bind-y # # install DNS service 2, configure the main configuration file / etc/named.conf [root@localhost conf] # vim / etc/named.conf # # main configuration file options {listen-on port 53 {any;} # # listen locally to all 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;} # # allow all 3, configure the zone configuration file (etc/named.rfc1912.zones) [root@localhost conf] # vim / etc/named.rfc1912.zones # # configure the zone configuration file zone "localhost" IN {# # copy the template to the following type master; file "named.localhost" Allow-update {none;};}; zone "kgc.com" IN {# # modify localhost to kgc.com type master; file "kgc.com.zone"; # # create region data profile allow-update {none 4. Edit the zone data configuration file (kgc.com.zone) [root@localhost conf] # cd / var/named [root@localhost named] # cp-p named.localhost kgc.com.zone # # copy template for kgc.com.zone [root@localhost named] # vim kgc.com.zone # # Edit the zone data configuration file $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.13.128 # # Delete ipv6 add domain name resolution address to native 5 Turn off the firewall and enable the service [root@localhost named] # systemctl start named # # enable the dns service [root@localhost named] # systemctl stop firewalld.service # # turn off the firewall [root@localhost named] # setenforce 0 # # turn off the enhanced feature 6, and use the win10 test machine to test

Authorization-based access control configuration steps are basically consistent with Apache to generate user password authentication files, modify the main configuration file to the corresponding directory, add authentication configuration items to restart the service, and access test 1 Modify the main configuration file [root@localhost ~] # cd / usr/local/nginx/conf # # change to the profile directory [root@localhost conf] # vim nginx.conf # # modify the Nginx configuration file location / {auth_basic "secret" # # Verification type auth_basic_user_file / usr/local/nginx/passwd.db; # # verify file path root html; index index.html index.htm } two, install the httpd-tools toolkit Set password authentication file [root@localhost conf] # yum install httpd-tools-y # # installation kit [root@localhost conf] # htpasswd-c / usr/local/nginx/passwd.db test # # set password authentication file New password: # # enter password Re-type new password: # # confirm password Adding password for user test [root@localhost conf] # cat / usr/local/nginx/passwd.db # # View password authentication file test:$apr1 $LqqHZeX3 $24E7/HeacTVRzKA7nvSgY/ [root@localhost conf] # service nginx stop # # disable service [root@localhost conf] # service nginx start # # enable service 3 Use win10 testing machine to test

Thank you for reading!

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