0x00 概述
以前做的一个实验,完成了在redhat下配置http服务器,并实现改变端口,域名代替ip等操作,有需要的可以参考一下。
0x01 改变端口号
[root@mail Desktop]# service httpd status
httpd (pid 4952) is running…
用ip直接访问网站,默认80端口
改变端口号,改成8888
80已经无法访问
成功访问
具体配置
[root@mail Desktop]# yum -y install policycoreutils-python
yum whatprovides /usr/sbin/semanage or yum provides /usr/sbin/semanage
[root@mail Desktop]# semanage port -l|grep http
http_cache_port_t tcp 3128, 8080, 8118, 8123, 10001-10010
http_cache_port_t udp 3130
http_port_t tcp 80, 443, 488, 8008, 8009, 8443
pegasus_http_port_t tcp 5988
pegasus_https_port_t tcp 5989
没8888
[root@mail Desktop]# semanage port -a -t http_port_t -p tcp 8888
[root@mail Desktop]# semanage port -l|grep http
http_cache_port_t tcp 3128, 8080, 8118, 8123, 10001-10010
http_cache_port_t udp 3130
http_port_t tcp 8888, 80, 443, 488, 8008, 8009, 8443
pegasus_http_port_t tcp 5988
pegasus_https_port_t tcp 5989
搞定!也可以使用关闭selinux来改变端口(不太安全)
0x02 域名代替ip
域名:www.gdhy.col
具体操作:
向正向解析文件加入一条A记录
$TTL 86400
gdhy.col. IN SOA dns.gdhy.col. root.gdhy.col (
20100820 ;serial
1H ;refresh
15M ;retry
1W ;expire
1D) ;minimun
gdhy.col. IN NS dns.gdhy.col.
dns IN A 10.0.165.253
@ IN MX 10 mail.gdhy.col.
mail IN A 10.0.165.253
www IN A 10.0.165.253
修改httpd.conf的servername的值
#
ServerName www.gdhy.col:8888
搞定!
0x03 配置虚拟主机
1. 基于ip
只有1个内网ip,算了
大概配置就这样:
<VirtualHost 10.0.165.252:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /var/www/html/vt1
DirectoryIndex index.html
ServerName www.vvtt1.com
ErrorLog logs/dummy-host.example.com-error_log
CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>
<VirtualHost 10.0.165.251:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /var/www/html/vt2
DirectoryIndex index.html
ServerName www.vvtt2.com
ErrorLog logs/dummy-host.example.com-error_log
CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>
2. 基于域名
通过www.vvtt1.com和www.vvtt2.com可以分别访问不同目录和主页
具体步骤:
配置正向解析文件,在named.comf加入这两个域zone
$TTL 86400
vvtt2.com. IN SOA dns.vvtt2.com. root.vvtt2.com (
20100820 ;serial
1H ;refresh
15M ;retry
1W ;expire
1D) ;minimun
vvtt2.com. IN NS dns.vvtt2.com.
dns IN A 10.0.165.253
www IN A 10.0.165.253
$TTL 86400
vvtt1.com. IN SOA dns.vvtt1.com. root.vvtt1.com (
20100820 ;serial
1H ;refresh
15M ;retry
1W ;expire
1D) ;minimun
vvtt1.com. IN NS dns.vvtt1.com.
dns IN A 10.0.165.253
www IN A 10.0.165.253
//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
options {
listen-on port 53 { any; };
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”;
allow-query { 0.0.0.0/0; };
recursion yes;
dnssec-enable yes;
dnssec-validation yes;
dnssec-lookaside auto;
/* Path to ISC DLV key */
bindkeys-file “/etc/named.iscdlv.key”;
managed-keys-directory “/var/named/dynamic”;
};
logging {
channel default_debug {
file “data/named.run”;
severity dynamic;
};
};
zone “gdhy.col” {
type master;
file “gdhy.col”;
};
zone “165.0.10.in-addr.arpa” {
type master;
file “165.0.10”;
};
zone “vvtt1.com” {
type master;
file “vvtt1.com”;
};
zone “vvtt2.com” {
type master;
file “vvtt2.com”;
};
include “/etc/named.rfc1912.zones”;
include “/etc/named.root.key”;
httpd.conf:
NameVirtualHost 10.0.165.253
<Virtualhost 10.0.165.253>
DocumentRoot /var/www/html/vt1
DirectoryIndex index.html
ServerName www.vvtt1.com
ServerAdmin root@vvtt1.com
ErrorLog logs/www.vvtt1.com-error_log
CustomLog logs/www.vvtt1.com-access_log common
</Virtualhost>
<Virtualhost 10.0.165.253>
DocumentRoot /var/www/html/vt2
DirectoryIndex index.html
ServerName www.vvtt2.com
ServerAdmin root@vvtt2.com
ErrorLog logs/www.vvtt2.com-error_log
CustomLog logs/www.vvtt2.com-access_log common
</Virtualhost>
加入上面内容
3.基于端口号
8881和8882端口都成功访问
具体步骤;
Listen 8881
Listen 8882
<Virtualhost 10.0.165.253:8881>
DocumentRoot /var/www/html/port8881
DirectoryIndex index.html
ServerAdmin root@vvtt1.com
ErrorLog logs/www.vvtt1.com-error_log
CustomLog logs/www.vvtt1.com-access_log common
</Virtualhost>
<Virtualhost 10.0.165.253:8882>
DocumentRoot /var/www/html/port8882
DirectoryIndex index.html
ServerAdmin root@vvtt2.com
ErrorLog logs/www.vvtt2.com-error_log
CustomLog logs/www.vvtt2.com-access_log common
</Virtualhost>
0x04 结语
linux服务器配置说难也不难,说简单也不简单……,需要细心和耐心,有时一个小小的错或者不当就gg,接下来可能会整理一系列服务器配置发出来,有需要就可以参考一下,少走弯路,最近真是so busy。