人妖在线一区,国产日韩欧美一区二区综合在线,国产啪精品视频网站免费,欧美内射深插日本少妇

新聞動態(tài)

nginx容器配置文件獨(dú)立的實(shí)現(xiàn)

發(fā)布日期:2022-02-01 04:54 | 文章來源:源碼中國

創(chuàng)建一個(gè)容器

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

進(jìn)入web目錄,下載nginx包

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

解壓目錄

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

安裝依賴包

[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'

創(chuàng)建用戶

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

創(chuàng)建日志存放文件地址

[root@6ad47178bdd6 web]# mkdir log

編譯安裝

[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

查看目錄

[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

配置環(huán)境變量

[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

啟動服務(wù)

[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:*   

在容器上查看服務(wù)

[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

在宿主機(jī)上查看

[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

可以看到數(shù)據(jù)已同步

在宿主上上修改配置文件

創(chuàng)建一個(gè)名為xy的目錄,把游戲代碼復(fù)制到這個(gè)目錄下

[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

在創(chuàng)建一個(gè)目錄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

修改nginx.conf配置文件

[root@server1 conf]# vi nginx.conf
........
    server {
         listen       8080;
         server_name  test.example.com;
         location / {
             root   /web/nginx/html/test;  #容器內(nèi)文件地址
             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;   #容器內(nèi)文件地址
            index  index.html index.htm;
        }
.....

但是這樣修改有點(diǎn)問題,只映射了一個(gè)端口,還有一個(gè)端口沒有映射

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

怎么決絕呢?

把這個(gè)容器刪掉

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

這里的數(shù)據(jù)還在宿主機(jī)上

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

重新創(chuàng)建以一容器映射這個(gè)目錄

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

在宿主機(jī)上查看

[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

在容器里查看數(shù)據(jù)有沒有同步

[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
#數(shù)據(jù)以同步

啟動服務(wù)

#寫一個(gè)環(huán)境變量
[root@6ad47178bdd6 /]# cat /etc/profile.d/nginx.sh 
export PATH=/web/nginx/sbin:$PATH
#創(chuàng)建nginx用戶
[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:*   

訪問192.168.244.145:80

訪問192.168.244.145:8080

到此這篇關(guān)于nginx容器配置文件獨(dú)立的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)nginx容器配置文件獨(dú)立內(nèi)容請搜索本站以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持本站!

國外服務(wù)器租用

版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。

實(shí)時(shí)開通

自選配置、實(shí)時(shí)開通

免備案

全球線路精選!

全天候客戶服務(wù)

7x24全年不間斷在線

專屬顧問服務(wù)

1對1客戶咨詢顧問

在線
客服

在線客服:7*24小時(shí)在線

客服
熱線

400-630-3752
7*24小時(shí)客服服務(wù)熱線

關(guān)注
微信

關(guān)注官方微信
頂部