亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

 更新時間:2021年12月09日 08:36:10   作者:YSTWD_WY  
本文主要介紹了nginx容器配置文件獨立,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

創(chuàng)建一個容器

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

進入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

啟動服務

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

在容器上查看服務

[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

在宿主機上查看

[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)建一個名為xy的目錄,把游戲代碼復制到這個目錄下

[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)建一個目錄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;  #容器內文件地址
             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;   #容器內文件地址
            index  index.html index.htm;
        }
.....

但是這樣修改有點問題,只映射了一個端口,還有一個端口沒有映射

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

怎么決絕呢?

把這個容器刪掉

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

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

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

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

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

在宿主機上查看

[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ù)以同步

啟動服務

#寫一個環(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

在這里插入圖片描述

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

相關文章

  • 利用nginx+lua+redis實現(xiàn)反向代理方法教程

    利用nginx+lua+redis實現(xiàn)反向代理方法教程

    這篇文章主要給大家介紹了利用nginx+lua+redis實現(xiàn)反向代理方法教程,文中介紹的非常詳細,對大家具有一定的參考學習價值,需要的朋友們下面來一起看看吧。
    2017-05-05
  • Nginx隱藏server頭信息的實現(xiàn)

    Nginx隱藏server頭信息的實現(xiàn)

    本文主要介紹了Nginx隱藏server頭信息的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2023-01-01
  • Nginx服務器設置網站驗證訪問的方法

    Nginx服務器設置網站驗證訪問的方法

    這篇文章主要介紹了Nginx服務器設置網站驗證訪問的方法,通過設置密碼來要求登錄網站目錄的用戶進行驗證,需要的朋友可以參考下
    2015-07-07
  • nginx搭建文件服務器(保姆級)

    nginx搭建文件服務器(保姆級)

    我們在工作過程中,有許多大的鏡像或者安裝包等,搭建一個文件服務器,可以高效的儲存文件,本文就來介紹一下nginx搭建文件服務器,感興趣的可以了解一下
    2023-06-06
  • nginx+tomcat 通過域名訪問項目的實例

    nginx+tomcat 通過域名訪問項目的實例

    這篇文章主要介紹了nginx+tomcat 通過域名訪問項目的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-05-05
  • 利用nginx訪問日志如何記錄mysql中的用戶id詳解

    利用nginx訪問日志如何記錄mysql中的用戶id詳解

    這篇文章主要給大家介紹了關于利用nginx訪問日志如何記錄mysql中用戶id的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面跟著小編一起來學習學習吧。
    2017-07-07
  • CentOS7下非編譯安裝Nginx的圖文教程

    CentOS7下非編譯安裝Nginx的圖文教程

    這篇文章主要為大家詳細介紹了CentOS7下非編譯安裝Nginx的圖文教程,文中通過示例圖片進行了詳細講解,有需要的小伙伴可以跟隨小編一起學習一下
    2023-10-10
  • Nginx的405 not allowed錯誤解決方法

    Nginx的405 not allowed錯誤解決方法

    本文主要介紹了Nginx的405 not allowed錯誤解決方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2023-05-05
  • 如何實現(xiàn)Nginx同一端口同時支持http與https協(xié)議

    如何實現(xiàn)Nginx同一端口同時支持http與https協(xié)議

    最近有一個需求,需要讓一個端口的http服務支持https訪問,本文就來介紹一下如何實現(xiàn)Nginx同一端口同時支持http與https協(xié)議,感興趣的可以了解一下
    2023-11-11
  • 分析nginx日志并屏蔽采集者ip(nginx屏蔽ip配置實例)

    分析nginx日志并屏蔽采集者ip(nginx屏蔽ip配置實例)

    這篇文章主要介紹了分析nginx日志并屏蔽采集者ip(nginx屏蔽ip配置實例),本文先是講解了分析需要屏蔽日志的方法,然后講解了Nginx中屏蔽IP的配置方法,需要的朋友可以參考下
    2015-02-02

最新評論