nginx docker 代理
发布时间:2021-07-19, 17:22:35 分类:Linux | 编辑 off 网址 | 辅助
图集1/1
正文 895字数 516,371阅读
server {
listen 80;
server_name 1.com;
location / {
#root /usr/share/nginx/html;
#index index.html index.htm index.php;
#proxy_set_header X-Real-IP $remote_addr;
#proxy_set_header Host $http_host;
#proxy_pass http://127.0.0.1:801;
proxy_pass http://172.20.0.1:801;
#proxy_pass http://172.20.0.1;
}
}
Run code
Cut to clipboard
用nginx docker 做反向代理出现502 Bad Gateway
nginx在docker中,不能使用127.0.0.1:801来访问宿主机里的应用,
docker内部实际上实现了一个虚拟网桥docker0,
所以要通过宿主机内网地址(172.20.0.1)来访问
2021/07/19 06:49:36 [error] 7#7: *1 open() "/home/wwwroot/favicon.ico" failed (2: No such file or directory), client: 172.20.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "127.0.0.1:801", referrer: "http://127.0.0.1:801/1.php"
Run code
Cut to clipboard
(支付宝)给作者钱财以资鼓励 (微信)→
有过 4 条评论 »
Docker教程:使用Docker容器运行Nginx并实现反向代理
镜像中nginx.conf配置文件路径 /etc/nginx/nginx.conf default.conf配置文件的路径 /etc/nginx/conf.d/default.conf 默认首页文件夹html路径 /usr/share/nginx/html 日志文件路径 /var/log/nginx
# 普通的挂载方式 docker run --name mynginx2 --mount source=/var/www,target==/usr/share/nginx/html,readonly \ --mount source=/var/nginx/conf,target=/etc/nginx/conf,readonly -p 80:80 -d nginx
location / { if (!-e $request_filename){ rewrite ^(.*)$ /index.php?s=$1 last; break; } }
tp3.2 nginx 伪静态
location / { if (!-e $request_filename) { rewrite ^/index.php(.*)$ /index.php?s=$1 last; rewrite ^(.*)$ /index.php?s=$1 last; #rewrite ^(.*)$ /index.php$1 break; break; } }
server { listen 80; server_name tp tp.com tp.net tp.org www.tp.com www.tp.net www.tp.org; root /www/root/develop/tp/Public; charset UTF-8; location / { if (!-e $request_filename){ rewrite ^/(.*)$ /index.php?s=/$1 last; } index index.php; } include php; include error; }