您好,登錄后才能下訂單哦!
這篇文章給大家介紹在docker中使用 nginx實現部署多個站點,內容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
nginx的配置文件
nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name www.dcssn.com; location / { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://47.92.69.112:8080; } } server { listen 80; server_name www.xhxf119.com; location / { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://47.92.69.112:8081; } } }
然后把這個文件保存到/host/path/ 目錄下
docker run --name my-custom-nginx-container -v /host/path/nginx.conf:/etc/nginx/nginx.conf:ro -d -p 80:80 nginx
大概流程就是這樣了 就可以直接輸入 www.dcssn.com 或者 www.xhxf119.com 訪問了
補充知識:docker配置nginx支持多個子域名對應不同的項目目錄
有機會要弄一個反向代理分發
具體的php與nginx配置請看本人博客里的搭建
cd /root/nginx/conf/conf.d
vim runoob-test-php.conf
runoob-test-php.conf文件內容,其實就是子域名對應目錄就行
server { listen 80; server_name www.liuyuanshan.top; location / { #proxy_pass http://106.52.36.65:80; root /usr/share/nginx/html; index index.php index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { fastcgi_pass php:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name; include fastcgi_params; } } server { listen 80; server_name message.liuyuanshan.top; location / { root /usr/share/nginx/html/message/; index index.php index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { fastcgi_pass php:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/html/message/$fastcgi_script_name; include fastcgi_params; } } server { listen 80; server_name wordpress.liuyuanshan.top; location / { root /usr/share/nginx/html/wordpress/; index index.php index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { fastcgi_pass php:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/html/wordpress/$fastcgi_script_name; include fastcgi_params; } }
重啟docker的nginx容器
docker restart ngixn
關于在docker中使用 nginx實現部署多個站點就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。