FreeBSD: Nginx Virtual Hosting Configuration

2009-05-13 15:23:38来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折


Q. How do I configure
[url=javascript:;]Nginx[/url]
Web server for
[url=javascript:;]virtual[/url]
hosting (
[url=javascript:;]host[/url]
multiple websites under same IP address - name based virtual hosting)?
A. Nginx allows you to host more than one domain name on the same computer and on the same IP address. There are two basic methods of accomplishing virtual hosting: name-based, and IP address or ip-based. This tutorial covers name-based virtual hosting i.e.
you can hosts multiple websites (host names) for the same webserver IP address.
Nginx name-based virtual hosting configurations
You need to create directory structure as follows to host more than two websites under same IP address:
a] /websites : Host each domain under this directory. You need to create dirs as follows:
/websites/examples.com/http - Html /
[url=javascript:;]php[/url]
/ wordpress / forums files for example.com goes here.
/websites/examples.com/logs - Log files for example.com goes here.
/websites/examples.com/stats - awstats stats files for example.com goes here.
b] /usr/local/etc/nginx/vhosts: Host each domains configuration under this directory.
Your sample setup
IP address: 202.54.1.2
HTTP Port: 80
Domain1 : theos.in hosted at /websites/theos.in/http
Domain2 : cyberciti.biz hosted at /websites/cyberciti.biz/http
Create necessary directories
Type the following commands:
# D=/websites
# NROOT=/usr/local/etc/nginx
# mkdir $D
# mkdir $NROOT/vhosts
# mkdir /var/log/nginx/
# chow
[url=javascript:;]root[/url]
:www /var/log/nginx/
Create / update default cache all ngnix config file
Open /usr/local/etc/nginx/nginx.conf file, enter:
# vi /usr/local/etc/nginx/nginx.conf
Update it as follows:
user  www www;
worker_processes  1;

# main server error log
error_log /var/log/nginx/error.log ;
pid /var/run/nginx.pid;

events {
worker_connections  1024;
}

# main server config
http {
include       mime.types;
default_type  application/octet-stream;
log_format  main  '$remote_addr - $remote_user [$time_local] $request '
                      '"$status" $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

sendfile        on;
#tcp_nopush     on;

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:调整服务启动顺序的方法

下一篇:nginx location的匹配优先规则