温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

在docker中使用 nginx实现部署多个站点

发布时间:2020-11-19 14:55:32 来源:亿速云 阅读:440 作者:Leah 栏目:开发技术

这篇文章给大家介绍在docker中使用 nginx实现部署多个站点,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

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;
  }
 }
}

然后把这个文件保存到/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文件内容,其实就是子域名对应目录就行

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实现部署多个站点就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI