Apache Server Setup

Source: Internet
Author: User

[Apache]
#yum install-y httpd
#mkdir-P/data/www/html
#vim/data/www/html/test.html
Hello World
#vim/etc/httpd/conf/httpd.conf
DocumentRoot "/data/www/html"

<directory "/data/www/html" >
Require all granted
</Directory>

<ifmodule dir_module>
DirectoryIndex index.html test.html
</IfModule>
#semanage fcontext-a-T httpd_sys_content_t '/data (/.*)? '//Change security context
#restorecon-fvvr/westos/
#systemctl Restart Httpd.service
#curl-i localhost
http/1.1 OK
Date:sun, 06:58:08 GMT
server:apache/2.4.6 (Red Hat)
Last-modified:sun, 06:23:52 GMT
ETag: "28-5114dc6fc9141"
Accept-ranges:bytes
Content-length:40
content-type:text/html; Charset=utf-8
[Configure virtual Host]
#vim/etc/httpd/conf.d/virtual.conf

<virtualhost *:80>
ServerName www.sina.com
Serveralias Sina.com
Documentroot/virtual/www.sina.com/html
</VirtualHost>
<directory "/virtual/www.sina.com/html" >
Require all granted
</Directory>

<virtualhost *:80>
ServerName www.alibaba.com
Serveralias Alibaba.com
Documentroot/virtual/www.alibaba.com/html
</VirtualHost>
<directory "/virtual/www.alibaba.com/html" >
Require all granted
</Directory>

#vim/etc/httpd/conf.d/defualt.conf
<virtualhost _default_:80>
Documentroot/data/www/html
Errorlog logs/www.html.com.log//In/etc/httpd/logs/www.html.com.log

</VirtualHost>
<directory "/data/www/html" >
Require all granted
</Directory>
Configure user-based authentication
To create an Apache password file with two accounts:
#useradd Damin
#htpasswd-CM/ETC/HTTPD/.HTPASSWD Admin//First add-C to create a password file is not needed.
#htpasswd-M/ETC/HTTPD/.HTPASSWD test
#vim/etc/httpd/conf.d/virtual.conf
<Directory/virtual/www.sina.com/html>
AuthName "Please input your name and password!"
AuthType Basic
authuserfile/etc/httpd/.htpasswd
Require Valid-user
</Directory>
#systemctl Restart httpd

[Configure HTTPS]
#使用genkey实用程序 (distributed through the Crypto-utils package), generates a self-signed certificate and its associated
Private. For simplicity, Genkey will create a certificate in the "correct" location (/etc/pki/tls directory) and its
The associated key. Accordingly, the utility must be run as an authorized user (root).
#yum install-y crypto-utils Mod_ssl
#genkey www.alibaba.com
#ls-L/etc/pki/tls/private/www.alibaba.com.key
#ls-L/ETC/PKI/TLS/CERTS/WWW.ALIBABA.COM.CRT
Make sure that the two files are only readable by root
#vim/etc/httpd/conf.d/virtual.conf
All 80 port requests are redirected by HTTPS
<virtualhost *:80>
ServerName www.alibaba.com
Rewriteengine on
Rewriterule ^ (/.*) $ https://%{http_host}$1 [redirect=301]
</Virtualhost>
Encrypted port is 443
VirtualHost *:443>
ServerName www.alibaba.com
Documentroot/virtual/www/html
Sslengine on
Sslcertificatefile/etc/pki/tls/certs/www.alibaba.com.crt
Sslcertificatekeyfile/etc/pki/tls/private/www.alibaba.com.key
<directory "/virtual/www.alibaba.com/html" >
Require all granted
</Directory>
</VirtualHost>
<virtualhost *:80>
ServerName www.alibaba.com
Rewriteengine on
Rewriterule ^ (/.*) $ https://%{http_host}$1 [redirect=301]
</VirtualHost>
#systemctl Restart httpd













This article from "Love You in Time" blog, declined reprint!

Apache Server Setup

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.