nginx容器配置文件獨(dú)立的實(shí)現(xiàn)
創(chuàng)建一個容器
[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)建一個名為xy的目錄,把游戲代碼復(fù)制到這個目錄下
[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; #容器內(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)問題,只映射了一個端口,還有一個端口沒有映射
[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ù)還在宿主機(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 /]#
在宿主機(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ù)
#寫一個環(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)文章希望大家以后多多支持腳本之家!
相關(guān)文章
利用nginx+lua+redis實(shí)現(xiàn)反向代理方法教程
這篇文章主要給大家介紹了利用nginx+lua+redis實(shí)現(xiàn)反向代理方法教程,文中介紹的非常詳細(xì),對大家具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起看看吧。2017-05-05Nginx隱藏server頭信息的實(shí)現(xiàn)
本文主要介紹了Nginx隱藏server頭信息的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-01-01Nginx服務(wù)器設(shè)置網(wǎng)站驗(yàn)證訪問的方法
這篇文章主要介紹了Nginx服務(wù)器設(shè)置網(wǎng)站驗(yàn)證訪問的方法,通過設(shè)置密碼來要求登錄網(wǎng)站目錄的用戶進(jìn)行驗(yàn)證,需要的朋友可以參考下2015-07-07nginx+tomcat 通過域名訪問項(xiàng)目的實(shí)例
這篇文章主要介紹了nginx+tomcat 通過域名訪問項(xiàng)目的實(shí)例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-05-05如何實(shí)現(xiàn)Nginx同一端口同時支持http與https協(xié)議
最近有一個需求,需要讓一個端口的http服務(wù)支持https訪問,本文就來介紹一下如何實(shí)現(xiàn)Nginx同一端口同時支持http與https協(xié)議,感興趣的可以了解一下2023-11-11分析nginx日志并屏蔽采集者ip(nginx屏蔽ip配置實(shí)例)
這篇文章主要介紹了分析nginx日志并屏蔽采集者ip(nginx屏蔽ip配置實(shí)例),本文先是講解了分析需要屏蔽日志的方法,然后講解了Nginx中屏蔽IP的配置方法,需要的朋友可以參考下2015-02-02