配置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 虛擬主機配置的三種方式(基於域名)Nginx
- 詳解Nginx 虛擬主機配置的三種方式(基於埠)Nginx
- 詳解Nginx 虛擬主機配置的三種方式(基於IP)Nginx
- nginx虛擬主機實戰Nginx
- 007.Nginx虛擬主機Nginx
- Nginx虛擬主機常用配置(學習筆記四)Nginx筆記
- WordPress主機和共享虛擬主機不同在哪?
- 虛擬主機和VPS主機有哪些不同點呢
- VMware虛擬機器如何設定使主機和虛擬機器不同IP虛擬機
- nginx伺服器配置多個虛擬主機vhost的方法示例Nginx伺服器
- lnmp虛擬主機安全配置研究LNMP
- 虛擬主機和VPS主機之間的幾點不同
- Nginx中關於虛擬主機的一點冷門知識Nginx
- MySQL多例項配置MySql
- nginx基礎篇之虛擬主機實戰Nginx
- VPS主機與虛擬主機或伺服器有何不同呢?伺服器
- 基於 LNMP 的 Nginx 百萬併發之路 (三)基於域名的虛擬主機LNMPNginx
- Nginx執行控制虛擬主機和訪問控制Nginx
- Nginx配置虛擬主機有哪些步驟?linux伺服器入門學習NginxLinux伺服器
- 虛擬機器與電腦主機網路配置虛擬機
- 福音 虛擬主機
- 虛擬主機,VPS主機,獨立伺服器三種有什麼不同伺服器
- MySQL 多例項配置管理:MySql
- 挑選虛擬主機需要注意哪些事項
- 虛擬主機和獨立伺服器有什麼不同伺服器
- NGINX 如何遮蔽未被定義的虛擬主機的訪問Nginx
- 主機ping不了虛擬機器虛擬機
- Linux虛擬主機與Windows虛擬主機之間有什麼區別LinuxWindows
- tomcat中虛擬主機以及web應用程式的配置TomcatWeb
- 在CentOS 8上安裝與配置Apache虛擬主機CentOSApache
- 虛擬機器(三)虛擬機器配置靜態Ip虛擬機
- Tomcat—部署配置及優化(安裝部署;虛擬主機配置;優化)Tomcat優化
- vsftpd多例項多使用者不同許可權FTP
- 簡單介紹apache虛擬主機配置的三種方式Apache
- canal同步mysql,監聽單例項,多例項配置MySql單例
- 物理機和虛擬機器有什麼不同虛擬機
- 基於mysqld_multi實現MySQL 5.7.24多例項多程式配置MySql
- 虛擬主機和vps主機使用哪些人群?