apache配置多個網站

來源:互聯網
上載者:User

標籤:多個   地址   網域名稱解析   als   following   公眾號   src   disco   virtual   

序:這次項目主要是為了給用戶端添加一個地址,在公眾號裡面添加一個可以訪問的app下載頁面,說起來很簡單,但總不能為了這麼小的一個網站建立一個web伺服器吧!

現在開始配置,首先必須確認已經在Linux上搭建好了LAMP環境,並且有一個網站可以正常訪問,以我的apache-ubuntu為例,預設目錄是:/var/www/html/

來先明確這個新的網站該放在哪兒,我絕不建議繼續放到預設目錄下一個目錄,應該放在www下面,我這麼做的,

sudo mkdir /var/www/sunjob-app        //建立一個網站目錄

沒錯,我的新小網站的目錄就在這個sunjob-app下面吧

接下來先別著急去設定檔,去網域名稱購買網站修改解析,我的是萬網,添加網域名稱解析,

注意把記錄類型修改為cname,不是圖中的A,記錄就是網域名稱首碼,預設是www,我修改成了app,那麼最終訪問時候的請求地址就是:app.ygdiy.com(注意首碼變了)

網域名稱解析結束,儲存!

回到ubuntu伺服器,開始配置這個網域名稱解析的新網站:

cd /etc/apache2/sites-available/            //進入可擷取網站配置目錄下

//vim建立並修改一個設定檔,我直接命名成了新網站,但注意尾碼是.conf,因為在apache.conf中預設是include "*.conf"檔案的

//而nginx中nginx.conf配置了“include sites-enable/*”所以所有檔案都會被載入,apache只載入.conf尾碼的

vim ./app.ygdiy.conf

 

修改設定檔代碼如下:

# The ServerName directive sets the request scheme, hostname and port that# the server uses to identify itself. This is used when creating# redirection URLs. In the context of virtual hosts, the ServerName# specifies what hostname must appear in the request‘s Host: header to# match this virtual host. For the default virtual host (this file) this# value is not decisive as it is used as a last resort host regardless.# However, you must set it for any further virtual host explicitly.    ServerName app.ygdiy.com    ServerAdmin [email protected]    DocumentRoot /var/www/sunjob-app    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,    # error, crit, alert, emerg.    # It is also possible to configure the loglevel for particular    # modules, e.g.    #LogLevel info ssl:warn    ErrorLog ${APACHE_LOG_DIR}/error.log    CustomLog ${APACHE_LOG_DIR}/access.log combinedOptions Indexes FollowSymLinks MultiViews         AllowOverride all         Order allow,deny         allow from all# For most configuration files from conf-available/, which are    # enabled or disabled at a global level, it is possible to    # include a line for only one particular virtual host. For example the    # following line enables the CGI configuration for this host only    # after it has been globally disabled with "a2disconf".    #Include conf-available/serve-cgi-bin.conf

儲存退出到bash中,把站台連結到enable中:

sudo ln -s /etc/apache2/sites-available/app.ygdiy.conf /etc/apache2/sites-enabled/app.ygdiy.conf

配置ok了,注意設定檔中,DocumentRoot 必須是存在並且可以訪問的目錄,因為新網站存放在這裡頭,被apache提供給使用者訪問

另外,servername,設定成剛剛解析的新網域名稱名字,cname的那個,注意了喲

重啟apache

sudo service apache2 restart

 

最後把新網站的檔案拷貝到/var/www/sunjob-app/下,你們拷貝到自己命名配置的目錄下即可,瀏覽器輸入網站新網域名稱即可訪問了,最後獻上我的,晚安

 

apache配置多個網站

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.