Docker nginx implements one host to deploy multiple sites

Docker nginx implements one host to deploy multiple sites

The virtual machine I rented from a certain site is about to expire, and the renewal fee is more than 200 yuan. Thinking of buying a new server in Alibaba Cloud, I might as well transfer this one there as well. I will use the real domain name, and please don’t hack my website. Thank you.

Alibaba Cloud has deployed a site that can be directly accessed using the domain name www.dcssn.com. My idea is to use www.xhxf119.com to point to this host and access different services based on different domain names.

first

Domain name resolution must point to the IP address of this host.

Then

The service of www.dcssn.com opens port 8080, docker run -p 8080:80 weian

www.xhxf119.com service opens port 8081, docker run -p 8081:80 xinhua

www.dcssn.com:8080 can access www.xhxf119.com:8081 can also access

Next, write the nginx configuration file

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

Then save this file to the /host/path/ directory

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

The general process is like this. You can directly enter www.dcssn.com or www.xhxf119.com to visit

Additional knowledge: Docker configures nginx to support multiple subdomains corresponding to different project directories

There is a chance to get a reverse proxy distribution

For specific PHP and nginx configurations, please see the setup in my blog

cd /root/nginx/conf/conf.d

vim runoob-test-php.conf

The content of the runoob-test-php.conf file is actually the directory corresponding to the subdomain.

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

Restart Docker's nginx container

docker restart nginx

The above article about how to deploy multiple sites on one host using docker nginx is all I have to share with you. I hope it can give you a reference, and I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • Detailed explanation of the processing of the three Docker Nginx Logs
  • Docker Nginx container and Tomcat container to achieve load balancing and dynamic and static separation operations
  • Docker deploys nginx and mounts folders and file operations
  • Docker deployment nginx implementation process graphic and text detailed explanation
  • How to deploy Vue project using Docker image + nginx
  • Methods and steps to build nginx file server based on docker
  • How to build Nginx image server with Docker
  • Docker Nginx container production and deployment implementation method

<<:  Detailed steps for using AES.js in Vue

>>:  Detailed explanation of MySQL persistent statistics

Recommend

Summary of the execution issues between mysql max and where

Execution problem between mysql max and where Exe...

Don't forget to close the HTML tag

Building web pages that comply with Web standards ...

Detailed explanation of html printing related operations and implementation

The principle is to call the window.print() metho...

Detailed explanation of count without filter conditions in MySQL

count(*) accomplish 1. MyISAM: Stores the total n...

Detailed graphic explanation of sqlmap injection

Table of contents 1. We found that this website m...

The process of installing and configuring nginx in win10

1. Introduction Nginx is a free, open source, hig...

How to import txt into mysql in Linux

Preface When I was writing a small project yester...

How to modify the root user password in mysql 8.0.16 winx64 and Linux

Please handle basic operations such as connecting...

MySql 5.7.20 installation and configuration of data and my.ini files

1. First download from the official website of My...

Installation of mysql-community-server. 5.7.18-1.el6 under centos 6.5

Use the following command to check whether MySQL ...

Basic application methods of javascript embedded and external links

Table of contents Basic application of javascript...