Build Apache web service under Centos7

apache

Mainstream web software

IIS

  • Can provide Web site services and provide FTP, NMTP, SMTP and other service functions, but only supports Windows systems

nginx

  • Stability and rich features
  • Low system resources, low memory usage and strong concurrency

Apache

  • Cross-platform and security
  • Fast, reliable and simple API extension
  • Has a high market share of Web service software
  • The most used web service software in the world
  • Open source, cross-platform

Tomcat

  • Lightweight web service software
  • Used to develop and debug JSP code

deploy

Install Apache service program

[root@localhost ~]# yum install -y httpd

Start and set to self-start after boot

[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl enable httpd

Turn off firewall and kernel firewall

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0

At this point, you can enter your URL on the browser to access, if the setup is successful, the Apache default welcome interface will be displayed

Configure Service File

Related file directory

Service catalog /etc/httpd
Configuration file /etc/httpd/conf/httpd.conf
Website Data Directory / var / www / html
Access log /var/log/httpd/access_log
Error log /var/log/httpd/error_log

Main configuration file

Apache's main configuration file is /etc/httpd/conf/httpd.conf

There are the following parameters in the main configuration file

image-20210117154836115

Modify website data directory

Modify the path after DocumentRoot on line 119 of the main configuration document to the required path, and modify the path on line 123 to the required path (the required path must be the same)

After the modification is completed, the Apache service needs to be restarted to take effect


Personal user homepage function

Turn on the personal user home page function

[root@localhost ~]# vim /etc/httpd/conf.d/userdir.conf
  • Comment line 17 UserDir disabled

  • Enable UserDir public_html on line 23

Restart apache service

Create personal user website data

  • Switch to normal user
  • Create a public_html directory in the home directory of ordinary users
  • Write content
  • Restart apache
  • Grant ordinary user directory and public_html 777 permissions to other users to access, otherwise 403
  • Visit URL IP/~Username

Increase password security verification

  • Switch to normal user

  • Generate a password database (-c is used for the first generation)

    • htpasswd -c /etc/httpd/passwd username
  • Write the configuration file /etc/httpd/conf.d/userdir.conf

    <Directory "/home/*/public_html">
      AllowOverride all
      authuserfile /etc/httpd/passwd
      authname "My privately website"
      authtype basic
      require user linxprobe
    </Directory>

Virtual website hosting function

Based on IP address
  • Use the nmtui command to add multiple IP addresses to the network card (Manual mode)

  • Remember to restart the network card after setting, and then ping the IP just set

  • Create website data directories separately

    • /home/wwwroot/10
    • /home/wwwroot/20
    • /home/wwwroot/30
  • Write home page file in the directory

  • Describe the virtual host based on the IP address in the configuration file

    <VirtualHost 192.168.10.10>
    DocumentRoot /home/wwwroot/10
    ServerName www.linuxprobe.com
    <Directory /home/wwwroot/10>
    AllowOverride None
    Require all granted
    </Directory>
    </VirtualHost>
    <VirtualHost 192.168.10.20>
    ....
    </VirtualHost>
    <VirtualHost 192.168.10.30>
    .....
    </VirtualHost>
Port access
  • Create a web page directory and write different home page files
  • Enter the apache main configuration file, find Listen80 on line 42, and append
    • Listen 6111
    • Listen 6222
  • Just write the address and port number in the virtual host configuration file

Apache access control

  • Access control of Aoache network resources can be done based on the host name, IP address, and client characteristics

  • Commonly used are Order (sort), Allow (allow), Deny (deny), Satisfy (satisfy)

  • Add parameters at line 129 of the main configuration file

    <Directory "/var/www/html/server">
    SetEnvIF User-Agent "Internet Explorer" ie=1
    Order allow,deny
    Allow from env=ie
    </Directory>
  • Restart apache service

Guess you like

Origin blog.51cto.com/14784139/2666727