nginx的安裝及基本配置,及多個域名服務

centos6.x yum默認沒有nginx的軟件包
安裝方式:
到nginx下載頁面http://nginx.org/en/linux_packages.html#stable,複製CENTOS 6的nginx軟件源安裝包
運行命令:wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
安裝rpm包 yum install nginx-release-centos-6-0.el6.ngx.noarch.rpm -y , 此步實際只是加入了nginx的軟件包源
執行 yum install nginx -y 就能夠安裝好nginx了html

nginx默認安裝爲linux的服務
使用service nginx start, stop, restart, try-restart, reload, force-reload, status來操做nginxlinux

nginx的配置文件默認讀取/etc/nginx/nginx.conf文件
nginx的配置都是由 directives組成,directives由簡單指令或者區塊指令組成
簡單指令:listen 80;
區塊指令由{}包含,區塊指令又能夠包含多個簡單指令和區塊指令:nginx

http { server { }
}

http能夠有多個server,多個server能夠監聽多個端口在同一服務器爲多個應用提供服務。
但若是你同時有多個域名www.you.com,news.you.com, mail.you.com在同一個服務器進行服務,那麼www.you.com,mail.you.com:8080, news.you.com:81這樣的訪問方式顯然是不合適顯然是不合適的,幸運的是nginx已經提供了經過域名過濾的規則centos

server
{
    listen 80;
    server_name www.you.com;
    location / {
        #....
        proxy_pass http://localhost:8880;
    }
    ##### other directive
}

server
{
    listen 80;
    server_name news.you.com;
    location / {
        #....
        proxy_pass http://localhost:8881;
    }
    ##### other directive
}

server
{
    listen 80;
    server_name mail.you.com;
    location / {
        #....
        proxy_pass http://localhost:8882;
    }
    ##### other directive
}

最終分別運行各個應用監聽對應端口便可。服務器

相關文章
相關標籤/搜索