docker nginx 簡單的代理設置

nginx一種代理,雖然是開發,但是也要懂一些

這個地方我們通過docker 安裝nginx並且設置簡單的代理

如何安裝nginx我這個地方就不做太多的敘述

現在我有一個網址: 10.0.13.140:8090

我們可以看到的是端口號是8090

這裏我們做一個代理:通過10.0.13.140:8080/WebTest 也可以訪問上面的項目

這個應該如何實現,也就是我們的nginx的功能了

下面我們看如何通過nginx進行配置:

我這裏運行了容器,其中一個是nginx

我們進入這個容器:

[root@test tmp]# docker exec -it nginx bash
root@22b08550c481:/# cd /etc/nginx/
root@22b08550c481:/etc/nginx# ll
bash: ll: command not found
root@22b08550c481:/etc/nginx# ls
conf.d	fastcgi_params	koi-utf  koi-win  mime.types  modules  nginx.conf  scgi_params	uwsgi_params  win-utf

  我們可以看到的是有在/etc/nginx/ 有一個nginx.conf 文件和conf.d 文件夾

其中nginx.conf這個文件是nginx的配置文件,我們可以在這個裏面進行我們自己的配置

我們看一下這個文件

root@22b08550c481:/etc/nginx# cat nginx.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;

    include /etc/nginx/conf.d/*.conf;
}
root@22b08550c481:/etc/nginx# 

在最後一行,我們可以看到的是,這個文件裏面引入了/etc/nginx/conf.d/ 下面所有conf文件,也就是說我們可以在conf.d下面創建我們自己的conf文件

我們進入到conf.d目錄下繼續查看:

root@22b08550c481:/etc/nginx/conf.d# ls
default.conf

裏面有一個default.conf文件,我們可以把這個文件cp到docker容器外面進行修改,進行我們自己的配置

listen 是nginx監聽的端口,這個端口是docker的端口

charset utf-8  是編碼

server_name 是宿主機的IP地址

location / {

 proxy_pass  http://10.0.13.140:8090  --//這個是我們要需要映射的地址,或者說是原地址,映射之前的端口是8090

}

保存之後,我們把這個文件cp到nginx原來的目錄

然後重新啓動docker

你會發現我們通過8080也可以訪問上面的項目

希望對你有所幫助

轉自:http://www.read8686.com/pages/detail/371

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章