濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > docker nginx實(shí)現(xiàn)一個(gè)主機(jī)部署多個(gè)站點(diǎn)操作

docker nginx實(shí)現(xiàn)一個(gè)主機(jī)部署多個(gè)站點(diǎn)操作

熱門(mén)標(biāo)簽:新鄉(xiāng)牧野400電話申請(qǐng) 智能電銷(xiāo)機(jī)器人真的有用么 高德地圖標(biāo)注足跡怎么打標(biāo) 企業(yè)辦理400電話收費(fèi)標(biāo)準(zhǔn) 激光標(biāo)記地圖標(biāo)注 百度地圖底圖標(biāo)注 中國(guó)地圖標(biāo)注上各個(gè)省 撫州市城區(qū)地圖標(biāo)注 電銷(xiāo)智能機(jī)器人試用

在某站租賃的虛擬機(jī)快到期了,續(xù)費(fèi)得花200多,想到在阿里云新買(mǎi)的服務(wù)器,不如把這個(gè)也轉(zhuǎn)移過(guò)去。域名我就用真實(shí)的吧,大家別黑我網(wǎng)站就好了,謝謝各位了。

阿里云里面已經(jīng)用部署了一個(gè)站點(diǎn) 用域名 www.dcssn.com 就能直接訪問(wèn),我的想法是再用 www.xhxf119.com 指向這個(gè)主機(jī),根據(jù)域名的不同去訪問(wèn)不同的服務(wù)。

首先

域名解析都要指向這個(gè)主機(jī)的ip

然后

www.dcssn.com的服務(wù)開(kāi)啟8080端口,docker run -p 8080:80 weian

www.xhxf119.com的服務(wù)開(kāi)啟8081端口,docker run -p 8081:80 xinhua

用www.dcssn.com:8080 能正常訪問(wèn) www.xhxf119.com:8081也能正常訪問(wèn)

接下來(lái) 寫(xiě)nginx的配置文件

nginx.conf
worker_processes 1;
events {
 worker_connections 1024;
}
http {
 include  mime.types;
 default_type application/octet-stream;
 sendfile  on;
 keepalive_timeout 65;
 server
 {
  listen 80;
  server_name www.dcssn.com;
  location / {
  proxy_redirect off;
  proxy_set_header Host $host;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_pass http://47.92.69.112:8080;
  }
 }
 
 server
 {
  listen 80;
  server_name www.xhxf119.com;
  location / {
  proxy_redirect off;
  proxy_set_header Host $host;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_pass http://47.92.69.112:8081;
  }
 }
}

然后把這個(gè)文件保存到/host/path/ 目錄下

docker run --name my-custom-nginx-container -v /host/path/nginx.conf:/etc/nginx/nginx.conf:ro -d -p 80:80 nginx

大概流程就是這樣了 就可以直接輸入 www.dcssn.com 或者 www.xhxf119.com 訪問(wèn)了

補(bǔ)充知識(shí):docker配置nginx支持多個(gè)子域名對(duì)應(yīng)不同的項(xiàng)目目錄

有機(jī)會(huì)要弄一個(gè)反向代理分發(fā)

具體的php與nginx配置請(qǐng)看本人博客里的搭建

cd /root/nginx/conf/conf.d

vim runoob-test-php.conf

runoob-test-php.conf文件內(nèi)容,其實(shí)就是子域名對(duì)應(yīng)目錄就行

server {
 listen  80;
 server_name www.liuyuanshan.top;

 location / {
  #proxy_pass http://106.52.36.65:80;
  root /usr/share/nginx/html;
  index index.php index.html index.htm;
 }

 error_page 500 502 503 504 /50x.html;
 location = /50x.html {
  root /usr/share/nginx/html;
 }

 location ~ \.php$ {
  fastcgi_pass php:9000;
  fastcgi_index index.php;
  fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name;
  include  fastcgi_params;
 }
}

server {
 listen  80;
 server_name message.liuyuanshan.top;

 location / {
  root /usr/share/nginx/html/message/;
  index index.php index.html index.htm;
 }

 error_page 500 502 503 504 /50x.html;
 location = /50x.html {
  root /usr/share/nginx/html;
 }
 location ~ \.php$ {
  fastcgi_pass php:9000;
  fastcgi_index index.php;
  fastcgi_param SCRIPT_FILENAME /var/www/html/message/$fastcgi_script_name;
  include  fastcgi_params;
 }
}


server {
 listen  80;
 server_name wordpress.liuyuanshan.top;

 location / {
  root /usr/share/nginx/html/wordpress/;
  index index.php index.html index.htm;
 }

 error_page 500 502 503 504 /50x.html;
 location = /50x.html {
  root /usr/share/nginx/html;
 }
 location ~ \.php$ {
  fastcgi_pass php:9000;
  fastcgi_index index.php;
  fastcgi_param SCRIPT_FILENAME /var/www/html/wordpress/$fastcgi_script_name;
  include  fastcgi_params;
 }
}

重啟docker的nginx容器

docker restart ngixn

以上這篇docker nginx實(shí)現(xiàn)一個(gè)主機(jī)部署多個(gè)站點(diǎn)操作就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

標(biāo)簽:西安 臨汾 辛集 延安 海西 南通 邯鄲 忻州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《docker nginx實(shí)現(xiàn)一個(gè)主機(jī)部署多個(gè)站點(diǎn)操作》,本文關(guān)鍵詞  docker,nginx,實(shí)現(xiàn),一個(gè),主機(jī),;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《docker nginx實(shí)現(xiàn)一個(gè)主機(jī)部署多個(gè)站點(diǎn)操作》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于docker nginx實(shí)現(xiàn)一個(gè)主機(jī)部署多個(gè)站點(diǎn)操作的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    高碑店市| 洞口县| 莱芜市| 蕉岭县| 偃师市| 舞钢市| 安溪县| 扶余县| 马公市| 奈曼旗| 青浦区| 隆德县| 闽清县| 额尔古纳市| 正安县| 炎陵县| 贵州省| 扎赉特旗| 京山县| 搜索| 吉林市| 白河县| 江川县| 兴隆县| 龙岩市| 兰坪| 外汇| 翁牛特旗| 阳高县| 天镇县| 开封县| 沈丘县| 包头市| 崇左市| 梨树县| 博乐市| 耒阳市| 万全县| 顺昌县| 三门县| 文登市|