1,爲了將生產環境和開發區分開,方便開發,將利用DNS和Nginx代理作內網域名解析。html
環境要求:nginx
服務器:CentOS7 64位 IP:192.168.1.49git
DNSvim
Nginx1.1服務器
客戶端:CentOS7 64位 IP:192.168.1.45session
Gitlabcurl
2.1,安裝DNS服務maven
[root@local ~]# yum install bind bind-bind-libside
2.2,修改/etc/named.conf配置文件測試
[root@local ~]#vim /etc/named.conf
//
// 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 { 127.0.0.1; };//開啓監聽端口53,接受任意IP鏈接
// listen-on-v6 port 53 { ::1; };//支持IP V6
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 { localhost; };//容許IP查詢
/*
- If you are building an AUTHORITATIVE DNS server, do NOT enable recursion.
- If you are building a RECURSIVE (caching) DNS server, you need to enable
recursion.
- If your recursive DNS server has a public IP address, you MUST enable access
control to limit queries to your legitimate users. Failing to do so will
cause your server to become part of large scale DNS amplification
attacks. Implementing BCP38 within your network would greatly
reduce such attack surface
*/
recursion yes;
dnssec-enable no;
dnssec-validation no;
/* Path to ISC DLV key */
// bindkeys-file "/etc/named.iscdlv.key";
// managed-keys-directory "/var/named/dynamic";
// pid-file "/run/named/named.pid";
// session-keyfile "/run/named/session.key";
};
logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
zone "." IN {
type hint;
file "named.ca";
};
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
注:註釋掉以上信息
啓動DNS服務
[root@local ~]#systemctl start named.service
查看端口是否啓用
[root@local ~]#ss -tunl | grep :53
2.3,編輯/etc/named.rfc1912.zones配置文件,在文件尾部添加如下行
[root@local ~]#vim /etc/named.rfc1912.zones
zone "local.yaok.com" IN {
type master;
file "local.yaok.com.zone";
};
重讀配置文件
[root@local ~]#rndc reload
查看DNS狀態
[root@local ~]#rndc status
2.4編輯/var/named/local.yaok.com.zone 配置文件
[root@local ~]# vim /var/named/local.yaok.com.zone
檢查配置文件語法錯誤,沒有語法錯誤
[root@local ~]# named-checkzone "local.yaok.com" /var/named/local.yaok.com.zone
進入/var/named/目錄
[root@local ~]# cd /var/named/
更改local.yaok.com.zone 的改組爲named
[root@local named]# chown :named local.yaok.com.zone
修改local.yaok.com.zone 文件權限爲640
[root@local named]# chmod 640 local.yaok.com.zone
重讀配置文件
[root@local ~]#rndc reload
配置域名解析是否正確,能夠正常解析
[root@local named]# dig -t A local.yaok.com @192.168.1.49
3.1,安裝Nginx
[root@local ~]# yum install niginx
啓動Nginx服務
[root@local ~]# /usr/sbin/nginx
查看80端口是否正常啓動
[root@local ~]# ss -tunl |grep 80
先備份nginx.conf配置文件
[root@local ~]#cp /etc/nginx/nginx.conf{,.bak}
3.2,修改nginx.conf配置文件
[root@local ~]# vim /etc/nginx/nginx.conf
添加如下配置文件
upstream server {
server 192.168.1.45;
}
server {
listen 80;
server_name git.local.yaok.com;
location / {
proxy_pass http://server;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
測試Nginx語法是否有錯
[root@local usr]# sbin/nginx -t
重讀Nginx配置文件
[root@local usr]#sbin/nginx -s reload
3.3,檢測訪問結果是否正確
[root@local usr]# curl -i http://git.local.yaok.com
4,使用客戶端來訪問
3.4,修改nginx.conf配置文件
[root@local ~]# vim /etc/nginx/nginx.conf
upstream mavenserver {
server 192.168.0.6;
}
#maven
server {
listen 80;
server_name maven.yaok.com;
#root /nexus/index.html;
location / {
proxy_pass http://192.168.0.6:8081;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}