PrefaceNginx is an HTTP server designed for performance. Compared with Apache and lighttpd, it has the advantages of less memory usage and higher stability. Since we need to deploy nginx docker now, we hope that the server_name in the nginx configuration file can be dynamically modified before starting the container. How it worksNginx consists of a kernel and modules. The kernel is very small and concise, and its work is also very simple. It only maps client requests to a location block (location is a directive in the Nginx configuration for URL matching) by looking up the configuration file. Each directive configured in this location will start different modules to complete the corresponding work. Nginx modules are structurally divided into core modules, basic modules and third-party modules: Core modules: HTTP module, EVENT module and MAIL module Basic modules: HTTP Access module, HTTP FastCGI module, HTTP Proxy module and HTTP Rewrite module, Learn envsubst envsubst replaces the environment variables with the values of the specified tags in the file. [test] ip = ${ip} port = ${port} url = http://${ip}:${port}/index.html phone = ${phone} When executing [test] ip = 192.168.1.5 port = 8081 url = http://192.168.1.5:8081/index.html phone = 13522223334 You can also specify to replace only some environment variables, Apply nginx configuration file version: "3" services: nginx: image: nginx:1.20.1-alpine container_name: nginx ports: - 80:80 -443:443 environment: - NGINX_HOST=www.janbar.com - NGINX_PORT=80 volumes: - /root/janbar.temp:/etc/nginx/conf.d/janbar.temp command: /bin/sh -c "envsubst < /etc/nginx/conf.d/janbar.temp > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'" network_mode: bridge restart: always The contents of the server { listen ${NGINX_PORT}; listen [::]:${NGINX_PORT}; server_name ${NGINX_HOST}; location / { root /usr/share/nginx/html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } } According to the above server { listen 80; listen [::]:80; server_name www.janbar.com; location / { root /usr/share/nginx/html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } } SummarizeAfter the above operations, you can finally update the internal configuration file of the nginx docker container through environment variables. Mission accomplished! The above is the details of using environment variables in the nginx configuration file. For more information about nginx environment variables, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
<<: Notes on MySQL case sensitivity
>>: Two types of tab applications in web design
1. View openjdk rpm -qa|grep jdk 2. Delete openjd...
1. First, understand the overflow-wrap attribute ...
Development Pain Points During the development pr...
Download MySQL https://dev.mysql.com/downloads/my...
1. Horizontal center Public code: html: <div c...
webkit scrollbar style reset 1. The scrollbar con...
Preface Yesterday, there was a project that requi...
Table of contents Example 1 Example 2 Example 3 E...
Strictly speaking, nginx does not have a health c...
introduction It is okay to add or not add a semic...
Performance of union all in MySQL 5.6 Part 1:MySQ...
<br />In previous tutorials of 123WORDPRESS....
This article example shares the specific code of ...
1. Install libfastcommon-1.0.43. The installation...
After the article "This Will Be a Revolution&...