赞
踩
为什么要用nginx?现在hass已经用了8123,node-red用了1880,emqx用了18083。现在的接口太多了,我根本记不过来,所以用nginx进行管理访问。
当前,因为是在树莓派上运行,arm架构在源码安装的时候各种依赖以及替代依赖搞得头大,再次选择docker安装。
附上官方连接:官方链接
为了方便的修改配置文件等,所以使用的时候需要把一些关键文件,映射到本地文件夹。
新建一个nginx用来做本地映射,我的路径是/home/pi/opt/nginx
这里创建目录的时候直接创建到nginx文件夹就行了,保证nginx里面是空的,然后让他自己启动容器把容器中的文件复制到物理机文件夹,然后再次基础上我们再进行配置文件的修改。
现在开始执行命令启动nginx。现在就可以等待docker拉取镜像了,最好docker换一下源,这样速度会快。
sudo docker run -d --name nginx -p 10004:80 --net host nginx
现在访问80
端口
看到这个说明成功了。
现在容器里面已经有了默认的配置文件,现在复制出来到刚才创建的文件夹
sudo docker container cp nginx:/etc/nginx /home/pi/opt
正常的话你的物理机文件夹里已经有了。
现在把刚才用到的中间商docker容器给删了
sudo docker stop nginx
sudo docker rm nginx
你已经有了配置文件,现在就可以进行文件映射了
sudo docker run --name nginx -d -p 10004:80 --net host -v /opt/nginx:/etc/nginx nginx
然后再看你的浏览器80端口,如果ok了。说明安装成功。
这里有个教程连接:菜鸟教程-nginx配置
在这里我想实现的是访问http://localhost/hass的时候请求发到了http://localhost:8123。用到了反向代理功能。
因为nginx配置读取conf.d文件夹下所有.conf结尾的配置文件,所以我们不动原生的,直接新建一个。
在nginx/conf.d文件夹下有个default.conf直接复制进去
这是我定义的配置文件:
server {
listen 80;
listen [::]:80;
server_name http://192.168.1.24/;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
#最后加上/不然定位不到
location /hass/ {
#最后面加上/不然定位不到
proxy_pass http://192.168.1.24:8123/;
}
location /nodered/ {
proxy_pass http://192.168.1.24:1880/;
}
location /emqx/ {
proxy_pass http://192.168.1.24:1883/;
}
location /docker/ {
proxy_pass http://192.168.1.24:9000/;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
重启docker容器
sudo docker restart nginx
现在就ok了
树莓派可能会出现80端口占用。
一般来说你使用
sudo losf -i:80 ##得到使用80端口的进程PID
ps {PID} ##查看进程的详情信息
命令就可以看到具体的端口使用的命令。我这里是apache2
我直接
sudo systemctl disable apache2.service
就给关了,然后重启就行了。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。