CentOS 6 Apache https virtual host practice, centoshttps

Source: Internet
Author: User

CentOS 6 Apache https virtual host practice, centoshttps

Question:
1. Create an httpd server. Requirements:
Two name-based virtual hosts are provided:
(A) www1.buybybuy.com. The directory of the page file is/web/vhosts/www1. The error log is/var/log/httpd/www1.err and the access log is/var/log/httpd/www1.access;
(B) www2.buybybuy.com. The directory of the page file is/web/vhosts/www2. The error log is/var/log/httpd/www2.err and the access log is/var/log/httpd/www2.access;
(CEN creates its own main page file index.html for two virtual machines, with the corresponding host name respectively;
(D) Output httpdwork status information through www1.buybybuy.com/server-status, and only allow access using the account number password (status: status );

2. Provide https service for the above 2nd virtual hosts, so that users can access the web site securely through https;
(1) certificate authentication is required. The country (CN), State (Beijing), city (Beijing), and Organization (Quintin Ltd) used in the certificate are required );
(2) set the Department as Ops, host name as www2.buybybuy.com, mail as admin@buybybuy.com;

========================================================== ========================================================

 

Prepare the environment and materials:
CentOS 6 (either)
In Apache 2.2
Use the domain name buybybuy.com


1. Create an httpd server

Create the required Folder:
# Mkdir-p/web/vhosts/www {1, 2}


(A), (B)

Because the Server comes with httpd, no installation is required.
Therefore, you can directly edit the httpd configuration file httpd. conf.
# Vim/etc/httpd/conf/httpd. conf

Comment out:
DocumentRoot

Uncomment:
# NameVirtualHost *: 80

Modify:
ServerName localhost: 80

Add the following virtual host configuration at the bottom
<VirtualHost *: 80>
ServerAdmin admin@buybybuy.com
DocumentRoot/web/vhosts/www1
ServerName www1.buybybuy.com
ErrorLog logs/www1.err
CustomLog logs/www1.access combined
</VirtualHost>

<Directory/web/vhosts/www1>
Options Indexes FollowSymLinks
AllowOverride All
Order allow, deny
Allow from all
</Directory>

<VirtualHost *: 80>
ServerAdmin admin@buybybuy.com
DocumentRoot/web/vhosts/www2
ServerName www2.buybybuy.com
ErrorLog logs/www2.err
CustomLog logs/www2.access combined
</VirtualHost>

<Directory/web/vhosts/www2>
Options Indexes FollowSymLinks
AllowOverride All
Order allow, deny
Allow from all
</Directory>

Found after Configuration
Apache 403 error, (13) Permission denied: access to/denied
No problems were found after checking httpd. conf and directory permissions.
It was found that the system started SELINUX.

Temporarily disable SELINUX
Setenforce 0

Permanently close
Vim/etc/selinux/config
Modify
SELINUX = enforcing
Change
SELINUX = disabled

(C)

Create an index.html file in www1and www2respectively. The content is www1.buybybuy.com and www2.buybybuy.com.
# Vim/web/vhosts/www1/index.html
# Vim/web/vhosts/www2/index.html


(D)

Create an access account and follow the prompts
# Htpasswd-c/etc/httpd/conf. d/. htpasswd webadmin

Modify httpd. conf and add
<Location/server-status>
AuthType Basic
AuthName "Administrator privateeee"
AuthUserFile "/etc/httpd/conf. d/. htpasswd"
Require user "webadmin"
SetHandler server-status
Order deny, allow
Deny from all
Allow from 192.168.3.3
</Location>

 

2. Set www2.buybybuy.com to https.

You must use OpenSSL to generate a self-signed certificate to ensure that OpenSSL is installed.
# Httpd-M | grep ssl
If not, install
# Yum install mod_ssl openssl

Configure the CA Service on the CentOS A server, and then issue A certificate to the https of the current server (CentOS B.

CentOS:

Initialize the CA Service and create the required files (/etc/pki/CA /)
# Touch index.txt create an index file
# Echo 01> serial: Create a serial number File

CA self-signed certificate
Generate Private Key
# (Umask 077; openssl genrsa-out/etc/pki/CA/private/cakey. pem2048)
Use the private key to generate a signature certificate
# Openssl req-new-x509-key/etc/pki/CA/private/cakey. pem-days 7300-out/etc/pki/CA/cacert. pem

CentOS B:

# Mkdir/etc/httpd/ssl
# Cd/etc/httpd/ssl
Generate a key
# (Umask 007; openssl genrsa-out httpd. key 1024)
Generate request file
# Openssl req-new-key httpd. key-out httpd. csr


Country Name (2 letter code) [XX]: CN
State or Province Name (full name) []: Beijing
Locality Name (eg, city) [Default City]: Beijing
Organization Name (eg, company) [Default Company Ltd]: Quintin Ltd
Organizational Unit Name (eg, section) []: Ops
Common Name (eg, your name or your server's hostname) []: www2.buybybuy.com
Email Address []: admin@buybybuy.com

Send the generated file to the CA Server CentOS:
# Scp httpd. csr root@192.168.3.67:/tmp/


Return to CentOS:

Sign
# Openssl ca-in/tmp/httpd. csr-out/etc/pki/CA/certs/www2.buybybuy.com. crt-days 365
Returns the generated crt to CentOS B.
# Scp/etc/pki/CA/certs/www2.buybybuy.com. crt:/etc/httpd/ssl/


Return to CentOS B:

Configure httpd ssl configuration (ssl. conf ):

# Cd/etc/httpd/conf. d/
Backup
# Cp ssl. conf {,. bak}

Edit ssl. conf

Modify
<VirtualHost _ default _: 443>
Is
<VirtualHost *: 443>

DocumentRoot "/web/vhosts/www2"
ServerName www2.buybybuy.com

Certificate location
SSLCertificateFile/etc/pki/tls/certs/localhost. crt
=>
SSLCertificateFile/etc/httpd/ssl/www2.buybybuy.com. crt

Private Key location
SSLCertificateKeyFile/etc/pki/tls/private/localhost. key
=>
SSLCertificateKeyFile/etc/httpd/ssl/httpd. key


Check the configuration file syntax error after configuration is complete:
# Httpd-t

Restart httpd:
# Service httpd restart

Check whether port 443 is Enabled:
Ss-tnl

Use s_client to perform A test on CentOS:
# Openssl s_client-connect 192.168.3.60: 443-CAfile/etc/pki/CA/cacert. pem

GET, HTTP, 1.1
Host: www2.buybybuy.com


HTTP/1.1 200 OK
Date: Wed, 05 Oct 2016 11:20:16 GMT
Server: Apache/2.2.15 (CentOS)
Last-Modified: Fri, 30 Sep 2016 13:33:02 GMT
ETag: "bf4e8-21-53db9a230598a"
Accept-Ranges: bytes
Content-Length: 33
Connection: close
Content-Type: text/html; charset = UTF-8

Www2.buybybuy.com </br>
Welcome!

Test successful!

Access the format in a browser:
Https://www2.buybybuy.com

 

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.