379451314 发表于 2020-5-17 10:32:47

nginx反向代理配置

本帖最后由 379451314 于 2020-5-17 10:33 编辑

宽带分配了公网IP,就把unas的端口映射出去了,这样就可以公网访问了。我往公网映射了 管理界面、可道云、emby、docker、蚂蚁笔记等端口,但是各种端口映射出去带来安全隐患,不知道哪个服务爆出来漏洞,被黑客攻击了数据就不安全了。可以使用反向代理把其他服务只用一个端口映射到公网。

但是unas自带反向代理程序不好用,各种排版错误,也不知道哪里错误了。
前几天安装了一个onlyoffice,发现onlyoffice把nginx也装上了,而且还是自启动,就有了一个用nginx把这些服务用一个端口代理到公网上的想法,这样路由器只开一个端口就可以了。
教程如下。具备条件,会基础linux命令,命令行下修改配置文件。
一、在app管理器安装onlyoffice、或者自己安装nginx也行,(安装nginx方法自行搜索)
二、在/etc/nginx/conf.d下新建resver.conf文件。
三、resver.conf文件里面写入
upstream unas{
# 这里写你打开的端口号,好像写不写也没啥关系
# 这里举个例子,映射unas管理界面和emby服务
server 127.0.0.1:80;      
server 127.0.0.1:8088;
}

server {
listen 8090;
server_name localhost;

# 下面一行是你访问的端口号后面使用的路径,自行修改
location /emby/ {
# emby影音服务;
proxy_set_header Host $http_host;
# 这个地方修改你emby服务的路径,看你路径是多少自行修改
proxy_pass http://127.0.0.1:8088/;
proxy_set_header X-real-ip $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

location / {
# unas管理界面;
# 这个地方修改你unas管理界面地址
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1;
proxy_set_header X-real-ip $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

# 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;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
四、写完后保存,使用命令重启服务nginx -s reload
五、测试一下,直接访问http://IP:8090/就可以访问管理界面
访问http://域名:8090/emby/就可以实现访问emby服务。
其他服务自行研究
http://www.u-share.cn/forum.php?mod=image&aid=32220&size=300x300&key=c36029939ff52459&nocache=yes&type=fixnone


jimo 发表于 2020-6-3 09:35:46

大佬请问一下代理可以让外网访问的时候看不到端口号吗?

379451314 发表于 2020-7-15 17:50:35

jimo 发表于 2020-6-3 09:35
大佬请问一下代理可以让外网访问的时候看不到端口号吗?

除了80是默认端口号看不到,其他的都能看得到端口号
页: [1]
查看完整版本: nginx反向代理配置