這篇文章主要講解了“docker nginx服務如何部署”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“docker nginx服務如何部署”吧!
1.下載nginx
docker pull nginx
2.啟動nginx
docker run -d -m 2g -p 8888:80 --name lyjng nginx
3.配置映射
創建目錄: mkdir -p /root/lyjnginx/nginx/www /root/lyjnginx/nginx/logs /root/lyjnginx/nginx/conf
其中:
www: 目錄將映射為 nginx 容器配置的虛擬目錄。
logs: 目錄將映射為 nginx 容器的日志目錄。
conf: 目錄里的配置文件將映射為 nginx 容器的配置文件。
4.復制docker容器中的文件
[root@ambari-01 lyjnginx]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES cf7da4042664 nginx "/docker-entrypoint.…" 20 minutes ago Up 20 minutes 0.0.0.0:8888->80/tcp lyjng [root@ambari-01 lyjnginx]# docker cp cf7da4042664:/etc/nginx/nginx.conf /root/lyjnginx/nginx/conf/
5.部署命令
docker run -m 2g --rm -d -p 8889:80 --name nginx-test-web -v /root/lyjnginx/nginx/www:/usr/share/nginx/html -v /root/lyjnginx/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /root/lyjnginx/nginx/logs:/var/log/nginx nginx
命令說明:
-m : 設置容器占用內存
--rm:容器終止運行后,自動刪除容器文件。
-p 8889:80: 將容器的 80 端口映射到主機的8889端口.
--name nginx-test-web:將容器命名為 nginx-test-web
-v /root/lyjnginx/nginx/www:/usr/share/nginx/html:將我們自己創建的 www 目錄掛載到容器的 /usr/share/nginx/html。
-v /root/lyjnginx/nginx/conf/nginx.conf:/etc/nginx/nginx.conf:將我們自己創建的 nginx.conf 掛載到容器的 /etc/nginx/nginx.conf。
-v /root/lyjnginx/nginx/logs:/var/log/nginx:將我們自己創建的 logs 掛載到容器的 /var/log/nginx。
6.添加網頁 將vue打包的文件復制到/root/lyjnginx/nginx/www/ 這個目錄下就能訪問了
[root@ambari-01 conf]# cd /root/lyjnginx/nginx/www/ [root@ambari-01 www]# vim index.html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Nginx test !!!</title> </head> <body> <h2>我的第一個標題</h2> <p>我的第一個段落。</p> </body> </html>
7.問題nginx代理轉發一致報404不生效問題
vim /root/lyjnginx/nginx/conf/nginx.conf 這個配置文件注釋掉# include /etc/nginx/conf.d/*.conf;
# 這行必須注釋否則/etc/nginx/conf.d/*.conf 會覆蓋下面server{}中的配置
# include /etc/nginx/conf.d/*.conf;
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
# 這行必須注釋否則/etc/nginx/conf.d/*.conf 會覆蓋下面server{}中的配置
# include /etc/nginx/conf.d/*.conf;
#lyj add
server {
listen 80;
server_name localhost;
location / {
# root /root/lyjnginx/bigdata_product;
root /usr/share/nginx/html;
index index.html index.htm;
}
location /prod-api/ {
proxy_pass http://192.168.3.175:8002/;
}
location /prod-api-extract/ {
proxy_pass http://192.168.1.134:8003/;
}
location /prod-api-dataxJ/ {
proxy_pass http://192.168.3.173:8008/;
}
location /prod-api-datax/ {
proxy_pass http://192.168.1.134:9527/;
}
}
#lyj add
}感謝各位的閱讀,以上就是“docker nginx服務如何部署”的內容了,經過本文的學習后,相信大家對docker nginx服務如何部署這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。