服務器的多域名配置

1. 常用的WEB服務器有Apache和nginx,小編偏向使用nginx。日常開發機器使用的是windows,本地測試安裝的wamp,會用的Apache;生成環境是使用linux,一鍵安裝lnmp,所以使用了nginx。
2. Nginx是一個高性能、輕量級的HTTP和反向代理服務器,也是一個IMAP/POP3/SMTP服務器。
Apache是一款老牌的Web服務器軟件。它可以運行在幾乎所有廣泛使用的計算機平台上,由於其跨平台和安全性被廣泛使用,是最流行的Web服務器端軟件之一。
3. 首先要把域名指定到服務器的IP上
4. Nginx的域名配置
Nginx的配置文件是/usr/local/nginx/conf/nginx.conf,文件中
include vhost/*.conf;
可以把域名配置文件協助vhost文件下,為了區分開來,每個域名創建一個.conf文件,如mydomain.conf配置文件如下
server
{
listen 80 ;
server_name www.mydomain.com;
index index.html;
root /data/mydomain/wwwroot/default;
#error_page 404 /404.html;
include enable-php.conf;
location /nginx_status
{
stub_status on;
access_log off;
}
location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*.(js|css)?$
{
expires 12h;
}
location ~ /.
{
deny all;
}
access_log /data/wwwlogs/access.log ;
}
配置好監聽端口80,server_name,index,root,include enable-php.conf這是兼容php
多個域名配置多個conf文件即可。然后測試一下配置文件是否寫正確
nginx –t
沒問題了就可以重啟
/etc/init.d/nginx restart
5. Apache 配置
Apache配置文件在D:wamp64binapacheapache2.4.18confextrahttpd-vhosts.conf
配置文件里面有多個VirtualHost,每個VirtualHost對應一個域名,多個域名配置多個即可
<VirtualHost *:80>
ServerName mydomain.com
DocumentRoot D:/wamp64/www/mydomain/public
<Directory “D:/wamp64/www/mydomain/public/”>
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
6. 總之,服務器的多域名配置就這么簡單,如有遺漏,請多指正。
wxgzh:ludong86

