日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > Nginx >内容正文

Nginx

Nginx配置之基于域名的虚拟主机

發(fā)布時間:2024/4/13 Nginx 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Nginx配置之基于域名的虚拟主机 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

1、配置好DNS解析
[root@server ~]#?cat /etc/redhat-release?
Red Hat Enterprise Linux Server release 6.2 (Santiago)
[root@server ~]#?uname -r
2.6.32-220.el6.i686
[root@server ~]#?yum install bind* -y
[root@server ~]#?vim /etc/named.conf
[root@server ~]#?cat /etc/named.conf

[plain]?view plaincopy print?
  • options?{??
  • listen-on?port?53?{?any;?};??
  • listen-on-v6?port?53?{?any;?};??
  • 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?{?any;?};??
  • recursion?yes;??
  • ??
  • dnssec-enable?yes;??
  • dnssec-validation?yes;??
  • dnssec-lookaside?auto;??
  • ??
  • /*?Path?to?ISC?DLV?key?*/??
  • bindkeys-file?"/etc/named.iscdlv.key";??
  • };??
  • ??
  • logging?{??
  • channel?default_debug?{??
  • file?"data/named.run";??
  • severity?dynamic;??
  • };??
  • };??
  • ??
  • zone?"."?IN?{??
  • type?hint;??
  • file?"named.ca";??
  • };??
  • ??
  • zone?"sxkeji.com.cn"?IN?{??
  • type?master;??
  • file?"sxkeji.com.cn.zone";??
  • };??
  • [root@server ~]#?cp /var/named/named.localhost /var/named/sxkeji.com.cn.zone
    [root@server ~]#?vim /var/named/sxkeji.com.cn.zone
    [root@server ~]#?cat /var/named/sxkeji.com.cn.zone?

    [plain]?view plaincopy print?
  • $TTL?1D??
  • @???IN?SOA??sxkeji.com.cn?rname.invalid.?(??
  • ????????????????????0???;?serial??
  • ????????????????????1D??;?refresh??
  • ????????????????????1H??;?retry??
  • ????????????????????1W??;?expire??
  • ????????????????????3H?)????;?minimum??
  • ????NS??@?????
  • @???A???192.168.10.199????
  • www?A???????192.168.10.199????
  • mail????A???????192.168.10.199????
  • [root@server ~]#?service named restart

    測試DNS解析是否成功
    [root@server ~]#?host www.sxkeji.com.cn
    www.sxkeji.com.cn has address 192.168.10.199
    [root@server ~]#?host mail.sxkeji.com.cn
    mail.sxkeji.com.cn has address 192.168.10.199
    [root@server ~]#

    2、配置Nginx虛擬主機(jī)
    [root@server ~]#?vim /usr/local/nginx/conf/nginx.conf
    [root@server ~]#?grep -vE "#|^$" /usr/local/nginx/conf/nginx.conf

    worker_processes? 1;
    events {
    ??? worker_connections? 1024;
    }
    http {
    ??? include?????? mime.types;
    ??? default_type? application/octet-stream;
    ??? sendfile??????? on;
    ??? keepalive_timeout? 65;
    ??? server {
    ??????? listen?????? 80;
    ??????? server_name? localhost;
    ??????? location / {
    ??????????? root?? html;
    ??????????? index? index.html index.htm;
    ??????? }
    ??????? error_page?? 500 502 503 504? /50x.html;
    ??????? location = /50x.html {
    ??????????? root?? html;
    ??????? }
    ?? ?
    ??? }
    ??? server {
    ??????? listen?????? 80;
    ??????? server_name? mail.sxkeji.com.cn;
    ??????? location / {
    ??????????? root?? /usr/local/nginx/html/mail.sxkeji.com;
    ??????????? index? index.html index.htm;
    ??????? }
    ?? ?}
    ?? ?include /usr/local/nginx/conf/vhosts/sxkeji.conf;?

    #include這里是模塊化的,把虛擬主機(jī)獨立成一個配置文件

    #上面斜體server部分是在主配置文件中直接實現(xiàn)虛擬主機(jī)
    }
    [root@server ~]#?cat /usr/local/nginx/conf/vhosts/sxkeji.conf?#vhosts目錄需要自己建立,主頁目錄也是需要自己建立的

    [plain]?view plaincopy print?
  • server?{??
  • listen?80;??
  • server_name?www.sxkeji.com.cn;??
  • access_log?logs/sxkeji.com.log;??
  • ??
  • location?/?{??
  • index?index.html;??
  • root?/usr/local/nginx/html/sxkeji.com;??
  • }??
  • }??
  • [root@server ~]#?

    3、測試是否成功
    [root@server ~]#?kill -HUP `cat /usr/local/nginx/logs/nginx.pid`?#重啟nginx
    [root@server ~]#?vim /usr/local/nginx/html/sxkeji.com/index.html?
    [root@server ~]#?vim /usr/local/nginx/html/mail.sxkeji.com/index.html?
    [root@server ~]#?cat /usr/local/nginx/html/mail.sxkeji.com/index.html
    mail.sxkeji.com.cn
    [root@server ~]#?cat /usr/local/nginx/html/sxkeji.com/index.html?
    www.sxkeji.com.cn
    [root@server ~]#?elinks --dump 127.0.0.1
    hello!
    [root@server ~]#?elinks --dump mail.sxkeji.com.cn
    mail.sxkeji.com.cn
    [root@server ~]#?elinks --dump www.sxkeji.com.cn
    www.sxkeji.com.cn
    [root@server ~]#?

    ########如此便可以收工了,下次繼續(xù)基于端口的虛擬主機(jī)配置########

    Nginx相關(guān)

    Nginx安裝配置:點擊打開鏈接

    Nginx虛擬主機(jī)配置:點擊打開鏈接

    總結(jié)

    以上是生活随笔為你收集整理的Nginx配置之基于域名的虚拟主机的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。