服务器的多域名配置

服务器的多域名配置

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

qrcode_for_gh_6bb1f39ae99c_344-1

猜你喜欢

转载自onetodo.iteye.com/blog/2334776