Linux-webserver Installation and Configuration

Source: Internet
Author: User

Apache
    1. Basic operations
explain Command
Installation Yum Install httpd
Start Service httpd Start
Stop it Service httpd Stop
  1. When the boot is complete

    • To see if a process exists:ps -ef | grep httpd
    • At this point in the local win address bar input 192.168.2.1 (that is, virtual machine IP), you will find that access is a failure
    • Then check if the port is listening: The sudo netstat -anpl | grep ‘http‘ port is listening, then why is the access unsuccessful?
    • When you close the firewall, and sudo service firewalld stop then enter the IP address again, you will see:
  2. Virtual Host Configuration

    • Enter: And cd /etc/httpd/ then to the cd conf directory, open the vim httpd.conf file, which is some configuration file, at this time if the permissions are not remember to mention the right

    • In this configuration file /virtual this to the keyword, configure a virtual host, just below this write

      <VirtualHost *:80>   ServerName www.imooc.test   DocumentRoot /data/www   <Directory "/data/www">       Options Indexes FollowSymLinks       AllowOverride None       Require all granted   </Directory></VirtualHost>
    • The above documentroot is the root directory of the file, because it does not exist, so create this directory sudo mkdir -p /data/www , to this WWW folder, Create a index.html file, write some content, save the exit, restart the server, at this time in the local win address bar access to ServerName, you will find that access is not successful, for what, because this domain name is virtual, to be configured,
    • This win to this directory c:\Windows\System32\Drivers\etc , find the host file, at the end of the add on it, for example 192.168.2.1 www.imooc.test , where this IP is the IP of the virtual machine, this place has a pit, the details see thishttps://jingyan.baidu.com/article/624e7459b194f134e8ba5a8e.html
    • If the access is unsuccessful, execute this command sudo setenforce 0 , this command mainly set loose mode

    • If you want to configure multiple virtual hosts, you can copy the above content multiple times, you should pay attention to the path yo
    • In this/etc/httpd directory there is a logs directory, log logs, into this directory, there are two files, Access_log, Error_log, respectively record this access and abnormal log, open tail -f error_log Here you will see some error information records

  3. Pseudo-static operation

    • To the cd /etc/httpd/modules class that will see all the modules

    • To cd /etc/httpd/conf.modules.d , this is the configuration of the module

    • Then go cd /etc/httpd/conf in, open the vim httpd.conf file, find the/loadmodule keyword,

    • Add under this keyword LoadModule rewrite_module modules/mod_rewrite.so ,

    • At this point in the configuration of the virtual host code to add, restart the server, that is, as long as the access address suffix name is. htmp, then go to index.html

      <VirtualHost *:80>   ServerName www.imooc.test   DocumentRoot /data/www   <Directory "/data/www">       Options Indexes FollowSymLinks       AllowOverride None       Require all granted       # 添加一下代码       <IfModule mod_rewrite.c>           RewriteEngine On           RewriteRule ^(.*).htmp$ index.html       </IfModule>   </Directory></VirtualHost>

Nginx
    1. Basic operations
explain Command
Installation Yum Install Nginx
Start Service Nginx Start
Stop it Service Nginx Stop
Overload Service Nginx Reload

Note that you need to add a CentOS7 Nginx resource library when installing

rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm, and then installyum install nginx

  1. After successful startup

    • To see if a process exists:ps -ef | grep nginx
    • At this point in the local win address bar input 192.168.2.1 (that is, virtual machine IP), you will see the Welcome interface
  2. Configure virtual host

    • enter: cd/etc/nginx/, open the vim nginx.conf file, which is a few configuration files,
    • and then to: Code>cd/etc/nginx/conf.d/, there will be a default file default.conf, where you can see the nginx default root directory, open vim/usr/share/nginx/html/ Index.html , this is the Nginx welcome interface
    • Copy the default file default.conf directly in this directory, for example imooc.conf, follow this to write it, and then reload
      server{Listen 80;    server_name www.imooc.test;    root/data/www;
     Index index.html index.htm;}  
    • If you want to configure multiple virtual hosts, repeat the above operation can be, and then copy one, to pay attention to the path,
    • if a virtual host to multi-port access to write a listen, or multi-domain name, in this domain name after more than write a can, to pay attention to the format, because the domain name here is virtual, so also add in the host, and the same as above
      server{Listen 80;    Listen 9999;    server_name Www.imooc.test www.imooc2.test;    root/data/www; Index index.html index.htm;}  

  3. Pseudo-Static

    • Or in the file where the virtual host is configured, the suffix name is only available at this time. Htmp will visit index.html page
    server{    listen  80;    server_name  www.imooc.test;    root /data/www;    index  index.html  index.htm;    location / {        rewrite ^(.*)\.htmp$ /index.html;    }}
  4. Formatting of the Log

    • Cd/etc/nginx, open nginx.conf file, after Log_format, you will see some format and the path of storage,/var/log/nginx/access.log, look at:tail -f /var/log/nginx/access.log
    • To customize the format, you only need to:
    • You can also specify the location of the log in the virtual host, so that it is easy to manage, remember from the overloaded server

    server{    listen  80;    server_name  www.imooc.test;    root /data/www;    index  index.html  index.htm;    # 指定日志关键字 存放的路径 日志格式的名字,就是上面自定义的    access_log /var/log/nginx/access_imooc.log imooc;    location / {        rewrite ^(.*)\.htmp$ /index.html    }}
  5. Reverse Proxy

    • Enter into cd /etc/nginx/conf.d , vim imooc.conf file, such as

      # 这个访问的实际ip地址,方便下面引用upstream imooc_hosts {    server 118.89.106.129:80;}server {    listen    80;    server_name  www.imooc.test;        root   /data/nginx;        index  index.html index.htm;    location / {       # 实际ip地址对应的Host        proxy_set_header Host www.54php.cn;        # 这个就是引用上面的方便管理        proxy_pass http://imooc_hosts;    }   }   
    • Overloaded server, Access www.imooc.test this URL, actually will be accessed www.54php.cn , at this time the former is as a proxy

  6. Load Balancing

    • If this time, again imooc_hosts add a URL, then in the first visit to www.imooc.test this URL, to the first corresponding URL, the second visit, go back to the second corresponding URL, the third or the first corresponding URL, ...

    • If you do not want this loop, want to make a server access more times, then add a keyword later, such as, so that the first URL is accessed five times times the second URL

       server 118.89.106.129:80 weight=5; server 101.132.110.127:80 weight=1;
  7. Debugging features

    • Usually when the error occurs, or in the virtual host configuration file, add the following content, reload the server, at this time on the page will show the requested domain name is what and the client address
    server {    listen    80;    # 添加下面的内容    add_header Content-Type "text/plain;charset=utf-8";    return 200 "$http_host $remote_addr";    server_name  www.imooc.test;    root   /data/nginx;    index  index.html index.htm;}   

?

?

Linux-webserver Installation and Configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.