服务器之家

服务器之家 > 正文

docker nginx实现一个主机部署多个站点操作

时间:2021-01-03 18:38     来源/作者:李浩洋93

在某站租赁的虚拟机快到期了,续费得花200多,想到在阿里云新买的服务器,不如把这个也转移过去。域名我就用真实的吧,大家别黑我网站就好了,谢谢各位了。

阿里云里面已经用部署了一个站点 用域名 www.dcssn.com 就能直接访问,我的想法是再用 www.xhxf119.com 指向这个主机,根据域名的不同去访问不同的服务。

首先

域名解析都要指向这个主机的ip

然后

www.dcssn.com的服务开启8080端口,docker run -p 8080:80 weian

www.xhxf119.com的服务开启8081端口,docker run -p 8081:80 xinhua

用www.dcssn.com:8080 能正常访问 www.xhxf119.com:8081也能正常访问

接下来 写nginx的配置文件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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;
  }
 }
}

然后把这个文件保存到/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 访问了

docker nginx实现一个主机部署多个站点操作

补充知识:docker配置nginx支持多个子域名对应不同的项目目录

有机会要弄一个反向代理分发

具体的php与nginx配置请看本人博客里的搭建

cd /root/nginx/conf/conf.d

vim runoob-test-php.conf

runoob-test-php.conf文件内容,其实就是子域名对应目录就行

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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实现一个主机部署多个站点操作就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/u011164906/article/details/73135836

标签:

相关文章

热门资讯

2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
Intellij idea2020永久破解,亲测可用!!!
Intellij idea2020永久破解,亲测可用!!! 2020-07-29
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
歪歪漫画vip账号共享2020_yy漫画免费账号密码共享
歪歪漫画vip账号共享2020_yy漫画免费账号密码共享 2020-04-07
电视剧《琉璃》全集在线观看 琉璃美人煞1-59集免费观看地址
电视剧《琉璃》全集在线观看 琉璃美人煞1-59集免费观看地址 2020-08-12
返回顶部