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

jQuery achieves the effect of advertisement scrolling up and down

This article shares the specific code of jQuery t...

A Brief Analysis of MySQL PHP Syntax

Let's first look at the basic syntax of the c...

Example code for using Nginx to implement 301 redirect to https root domain name

Based on SEO and security considerations, a 301 r...

An example of how Vue implements four-level navigation and verification code

Effect: First create five vue interfaces 1.home.v...

How to fill items in columns in CSS Grid Layout

Suppose we have n items and we have to sort these...

Discussion on the Issues of Image Button Submission and Form Repeated Submission

In many cases, in order to beautify the form, the ...

How to simulate enumeration with JS

Preface In current JavaScript, there is no concep...

A collection of information about forms and form submission operations in HTML

Here we introduce the knowledge about form elemen...

MySql knowledge points: transaction, index, lock principle and usage analysis

This article uses examples to explain the princip...

Detailed tutorial on installing the jenkins container in a docker environment

Recommended Docker learning materials: https://ww...

Example of implementing QR code scanning effects with CSS3

Online Preview https://jsrun.pro/AafKp/ First loo...

10 reasons why Linux is becoming more and more popular

Linux has been loved by more and more users. Why ...