配置nginx多实例(不同于虚拟主机),nginx虚拟主机
配置nginx多实例(不同于虚拟主机),nginx虚拟主机
配置nginx多实例[root@backup ~]# /application/nginx/sbin/nginx -h
nginx version: nginx/1.6.3
Usage: nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]
Options:
-?,-h : this help
-v : show version and exit
-V : show version and configure options then exit
-t : test configuration and exit
-q : suppress non-error messages during configuration testing
-s signal : send signal to a master process: stop, quit, reopen, reload
-p prefix : set prefix path (default: /application/nginx-1.6.3//)
-c filename : set configuration file (default: conf/nginx.conf)
-g directives : set global directives out of configuration file
指定配置文件启动nginx服务
-c filename : set configuration file (default: conf/nginx.conf)
1.1开始配置nginx多实例(配置端口,因为跟另个实例冲突)
-c指定其他的nginx配置文件
[root@backup cmsconf]# ../sbin/nginx -c /application/nginx/cmsconf/nginx.conf -t
nginx: the configuration file /application/nginx/cmsconf/nginx.conf syntax is ok
nginx: configuration file /application/nginx/cmsconf/nginx.conf test is successful
#启动另一个实例
[root@backup cmsconf]# ../sbin/nginx -c /application/nginx/cmsconf/nginx.conf
[root@backup cmsconf]# ps -ef|grep nginx|grep master
root 14664 1 0 13:46 ? 00:00:00 nginx: master process /application/nginx/sbin/nginx
root 22359 1 0 16:37 ? 00:00:00 nginx: master process ../sbin/nginx -c /application/nginx/cmsconf/nginx.conf
#创建站点目录
[root@backup www]# mkdir cms
[root@backup www]# echo "cms" >>cms/index.html
#然后在浏览器端访问站点http://cms.etiantian.org:8080/
访问结果:cms
(windows做域名解析192.168.0.251 cms.etiantina.org)
#cms日志
[root@backup www]# ll /app/logs/*cms*
-rw-r--r-- 1 root root 329 Feb 15 16:42 /app/logs/cms_access.log
-rw-r--r-- 1 root root 234 Feb 15 16:42 /app/logs/nginx_cms_error.lo
补充cms实例的配置文件。
主配置文件:
[root@backup www]# vi /application/nginx/cmsconf/extra/nginx-vhosts.conf
[root@backup www]# cat /application/nginx/cmsconf/nginx.conf
worker_processes 8;
user nginx nginx;
error_log /app/logs/nginx_cms_error.log;
events {
use epoll;
worker_connections 20480;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
log_format commonlog '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
keepalive_timeout 65;
include extra/nginx-vhosts.conf;
}
虚拟主机配置文件:
[root@backup www]# cat /application/nginx/cmsconf/extra/nginx-vhosts.conf
###CMS
server {
listen 8080;
server_name cms.etiantian.org;
location / {
root /data0/www/cms;
index index.html index.htm;
access_log /app/logs/cms_access.log commonlog;
}
}
1.2开始配置nginx多实例(新增主机ip,来避免IP冲突)
1.2.1新增IP地址
[root@backup www]# ifconfig eth0:249 192.168.0.249 up
[root@backup www]# ifconfig eth0:249
eth0:249 Link encap:Ethernet HWaddr 00:0C:29:67:7C:91
inet addr:192.168.0.249 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
1.2.2修改cms实例的虚拟主机配置文件。
就是在listen端口添加监听的IP和端口,例如:
正常的实例:listen 192.168.0.251:80
cms的实例:liten 192.168.0.249:80
这样就避免了冲突。
2.生产环境中nginx多实例的应用说明
当服务器资源有限,而且单个服务器的性能又没跑满,又希望http服务相对独立,此时就可以采用nginx多实例的方式。
在nginx的多实例中,我们可以采用普通用户非普通端口的方式启动nginx,然后在前端通过haproxy,netscaler,f5,
lvs(net模式),nginx(负载均衡模式)等软件来说负载均衡。
评论暂时关闭