配置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(負載均衡模式)等軟體來說負載均衡。
[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(負載均衡模式)等軟體來說負載均衡。
相關文章
- Nginx虛擬主機配置Nginx
- Nginx虛擬主機VirtualHost配置Nginx
- Nginx配置之基於域名的虛擬主機Nginx
- Nginx 虛擬主機配置的三種方式(基於域名)Nginx
- 詳解Nginx 虛擬主機配置的三種方式(基於埠)Nginx
- 詳解Nginx 虛擬主機配置的三種方式(基於IP)Nginx
- nginx虛擬主機實戰Nginx
- nginx之 nginx虛擬機器配置Nginx虛擬機
- Nginx虛擬主機常用配置(學習筆記四)Nginx筆記
- 007.Nginx虛擬主機Nginx
- Nginx實戰(一) 虛擬主機Nginx
- nginx多個虛擬主機noinputfilespecifiedNginx
- linux配置基於ip的虛擬主機Linux
- MySQL 5.6同一物理主機配置多例項MySql
- [php]apache虛擬主機配置PHPApache
- VMware虛擬機器如何設定使主機和虛擬機器不同IP虛擬機
- MySQL單機多例項配置MySql
- nginx伺服器配置多個虛擬主機vhost的方法示例Nginx伺服器
- MySQL單機多例項安裝並配置主從複製MySql
- Nginx中關於虛擬主機的一點冷門知識Nginx
- Ubuntu apache2配置虛擬主機UbuntuApache
- ubuntu14.04 lnmp nginx 虛擬主機(多站點 多域名) 配置UbuntuLNMPNginx
- nginx基礎篇之虛擬主機實戰Nginx
- 【Nginx】Nginx虛擬vhost配置檔案Nginx
- 基於 LNMP 的 Nginx 百萬併發之路 (三)基於域名的虛擬主機LNMPNginx
- VPS主機與虛擬主機或伺服器有何不同呢?伺服器
- Nginx執行控制虛擬主機和訪問控制Nginx
- MySQL多例項配置MySql
- 虛擬機器與電腦主機網路配置虛擬機
- 福音 虛擬主機
- 關於kangle虛擬主機系統與N點虛擬主機系統的比較
- 【Nginx】nginx虛擬機器設定Nginx虛擬機
- nginx(二):進階配置介紹–rewrite用法,壓縮,https虛擬主機等NginxHTTP
- 基於Linux的虛擬主機搭建Linux
- 利用mysqld_multi配置單機多例項MySql
- Linux下MySQL配置單機多例項LinuxMySql
- 當年的筆記_apache配置虛擬主機筆記Apache
- PHP實踐之路(二)apache虛擬主機配置PHPApache