Independent implementation of nginx container configuration file

Independent implementation of nginx container configuration file

Create a container

[root@server1 ~]# docker run -it --name nginx1 -v /opt/data/web2:/web -p 81:80 centos:latest /bin/bash
[root@608de4875036 /]#

Enter the web directory and download the nginx package

[root@608de4875036 web]# wget http://nginx.org/download/nginx-1.20.1.tar.gz

Unzip the directory

[root@608de4875036 web]# ls
nginx-1.20.1 nginx-1.20.1.tar.gz

Install dependency packages

[root@608de4875036 web]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++ make
[root@608de4875036 web]# yum -y groups mark install 'Development Tools'

Create User

[root@608de4875036 web]# useradd -r -M -s /sbin/nologin nginx
[root@608de4875036 web]# id nginx
uid=998(nginx) gid=996(nginx) groups=996(nginx)

Create a log storage file address

[root@6ad47178bdd6 web]# mkdir log

Compile and install

[root@608de4875036 web]# ls
log nginx-1.20.1 nginx-1.20.1.tar.gz
[root@608de4875036 web]# cd nginx-1.20.1
[root@608de4875036 nginx-1.20.1]# ls
auto conf html README
CHANGES configure LICENSE src
CHANGES.ru contrib man

[root@608de4875036 nginx-1.20.1]# ./configure \
--prefix=/web/nginx \
--user=nginx \
--group=nginx \
--with-debug \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_image_filter_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--http-log-path=/web/log/access.log \
--error-log-path=/web/log/error.log

[root@608de4875036 nginx-1.20.1]# make && make install

View Catalog

[root@6ad47178bdd6 web]# ls
log nginx nginx-1.20.1 nginx-1.20.1.tar.gz


[root@608de4875036 web]# cd nginx
[root@608de4875036 nginx]# ls
conf html logs sbin

Configuring environment variables

[root@608de4875036 nginx]# ls
conf html logs sbin
[root@608de4875036 nginx]# cd sbin/
[root@608de4875036 sbin]# ls
nginx
[root@608de4875036 sbin]# pwd
/web/nginx/sbin

[root@608de4875036 sbin]# echo "export PATH=/web/nginx/sbin:\$PATH" > /etc/profile.d/nginx.sh
[root@608de4875036 sbin]# source /etc/profile.d/nginx.sh
[root@608de4875036 sbin]# which nginx
/web/nginx/sbin/nginx

Start the service

[root@608de4875036 sbin]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process         
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*   

View services on the container

[root@608de4875036 web]# ls
nginx nginx-1.20.1 nginx-1.20.1.tar.gz
[root@608de4875036 web]# cd nginx
[root@608de4875036 nginx]# ls
client_body_temp html sbin
conf logs scgi_temp
fastcgi_temp proxy_temp uwsgi_temp

View on the host machine

[root@server1 ~]# cd /opt/data/
[root@server1 data]# ls
web1 web2
[root@server1 data]# cd web2
[root@server1 web2]# ls
log nginx nginx-1.20.1 nginx-1.20.1.tar.gz

[root@server1 web2]# cd nginx
[root@server1 nginx]# ls
client_body_temp html sbin
conf logs scgi_temp
fastcgi_temp proxy_temp uwsgi_temp

You can see that the data has been synchronized

Modify the configuration file on the host

Create a directory named xy and copy the game code into this directory

[root@server1 html]# pwd
/opt/data/web2/nginx/html
[root@server1 html]# mkdir yx
[root@server1 html]# cd yx
[root@server1 yx]# ls
image index.html js

Create a directory test

[root@server1 html]# mkdir test
[root@server1 html]# ls
[root@server1 html]# ls
50x.html index.html test yx
[root@server1 html]# mv 50x.html index.html test/
[root@server1 html]# ls
test yx

Modify the nginx.conf configuration file

[root@server1 conf]# vi nginx.conf

........

    server {
         listen 8080;
         server_name test.example.com;

         location / {
             root /web/nginx/html/test; #File address in the container index index.html index.htm;
         }
    }

   server {
        listen 80;
        server_name xy.example.com;

        #charset koi8-r;

        #access_log logs/host.access.log main;

        location / {
            root /web/nginx/html/yx; #File address in the container index index.html index.htm;
        }
.....

But there is a problem with this modification. Only one port is mapped, and the other port is not mapped.

[root@server1 conf]# docker port 608de4875036
80/tcp -> 0.0.0.0:81
80/tcp -> :::81

How to resolve it?

Delete this container

[root@server1 ~]# docker stop 608de4875036
608de4875036
[root@server1 ~]# docker rm 608de4875036
608de4875036

The data here is still on the host machine

[root@server1 web2]# ls
log nginx nginx-1.20.1 nginx-1.20.1.tar.gz

Recreate this directory as a container mapping

[root@server1 ~]# docker run -it --name nginx2 -v /opt/data/web2:/web -p 80:80 -p 8080:8080 centos:latest /bin/bash
[root@6ad47178bdd6 /]#

View on the host machine

[root@server1 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6ad47178bdd6 centos:latest "/bin/bash" 23 seconds ago Up 22 seconds 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp nginx2
[root@server1 ~]# docker port 6ad47178bdd6
80/tcp -> 0.0.0.0:80
80/tcp -> :::80
8080/tcp -> 0.0.0.0:8080
8080/tcp -> :::8080

Check whether the data is synchronized in the container

[root@6ad47178bdd6 /]# ls
bin home lost+found opt run sys var
dev lib media proc sbin tmp web
etc lib64 mnt root srv usr
[root@6ad47178bdd6 /]# cd web/
[root@6ad47178bdd6 web]# ls
nginx nginx-1.20.1 nginx-1.20.1.tar.gz
[root@6ad47178bdd6 web]# cd nginx
[root@6ad47178bdd6 nginx]# ls
client_body_temp html sbin
conf logs scgi_temp
fastcgi_temp proxy_temp uwsgi_temp
#Data synchronization

Start the service

#Write an environment variable [root@6ad47178bdd6 /]# cat /etc/profile.d/nginx.sh 
export PATH=/web/nginx/sbin:$PATH
#Create nginx user [root@6ad47178bdd6 /]# useradd -r -M -s /sbin/nologin nginx
[root@6ad47178bdd6 /]# nginx
[root@6ad47178bdd6 /]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process         
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*                            
LISTEN 0 128 0.0.0.0:8080 0.0.0.0:*   

Visit 192.168.244.145:80

insert image description here

Visit 192.168.244.145:8080

insert image description here

This is the end of this article about the implementation of independent nginx container configuration files. For more related independent nginx container configuration files, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Nginx configuration file detailed explanation and optimization suggestions guide
  • How to view nginx configuration file path and resource file path
  • Detailed explanation of Nginx configuration file
  • Detailed explanation of nginx configuration file interpretation
  • Detailed explanation of Nginx static file service configuration and optimization

<<:  A brief discussion on the invalidation or implicit conversion of MySQL integer and string indexes

>>:  A brief discussion on HTML titles, paragraphs, line breaks, horizontal lines, and special characters

Recommend

js canvas realizes slider verification

This article example shares the specific code of ...

Vue implements zip file download

This article example shares the specific code of ...

Solve the problem of Syn Flooding in MySQL database

Syn attack is the most common and most easily exp...

MySQL 5.5.27 winx64 installation and configuration method graphic tutorial

1. Installation Package MYSQL service download ad...

WeChat applet implementation anchor positioning function example

Preface In the development of small programs, we ...

The whole process of realizing website internationalization using Vite2 and Vue3

Table of contents Preface Install vue-i18n Config...

Docker solves the problem that the terminal cannot input Chinese

Preface: One day, I built a MySQL service in Dock...

MySQL 8.0.16 Win10 zip version installation and configuration graphic tutorial

This article shares with you the installation and...

Vue Beginner's Guide: Environment Building and Getting Started

Table of contents Initial Vue Building a Vue deve...

How is a SQL statement executed in MySQL?

Table of contents 1. Analysis of MySQL architectu...

Detailed steps for debugging VUE projects in IDEA

To debug js code, you need to write debugger in t...

Mysql accidental deletion of data solution and kill statement principle

mysql accidentally deleted data Using the delete ...