使用群晖访问ip或自定义域名时群晖默认会将80端口重定向向至5000或其他自定DSM端口:
访问 http://192.168.123.228/ -> http://192.168.123.228:5000/
由于群晖系统nginx配置优先级问题当使用 synology 应用程序门户 反向代理 自定义子域名时会出现以下问题:
访问 http://blog.gofancy.top/ -> http://blog.gofancy.top:5000/
nginx 会将子域名重定向到DSM端口
下面是取消将80端口重定向至DSM端口方法:
1.开启 ssh
2 win+R CMD 打开终端 使用 ssh 登录
ssh gofancy@ip
切换到root
sudo -i
3 修改nginx 模板文件
群晖会在重启后重置nginx配置 所以直接修改etc/nginx 配置是无效的
进入nginx模板文件目录:
cd /usr/syno/share/nginx/
编辑模板文件
vim WWWService.mustache
将相关重定向配置注释掉
#location ~ ^/$ {
# rewrite / http://$host:{{DSM.port}}/ redirect;
#}
#location ~ ^/$ {
# rewrite / https://$host:{{DSM.ssl.port}}/ redirect;
#}
文件最后看起来是这样的
server {
listen 80 default_server{{#reuseport}} reuseport{{/reuseport}};
listen [::]:80 default_server{{#reuseport}} reuseport{{/reuseport}};
gzip on;
{{> /usr/syno/share/nginx/WWW_Main}}
#location ~ ^/$ {
# rewrite / http://$host:{{DSM.port}}/ redirect;
#}
}
server {
listen 443 default_server ssl{{#reuseport}} reuseport{{/reuseport}};
listen [::]:443 default_server ssl{{#reuseport}} reuseport{{/reuseport}};
{{#DSM.https.compression}}
gzip on;
{{/DSM.https.compression}}
{{> /usr/syno/share/nginx/WWW_Main}}
#location ~ ^/$ {
# rewrite / https://$host:{{DSM.ssl.port}}/ redirect;
#}
}
:wq 保存
编辑文件
vim WWW_Main.mustache
注释相关配置
#location / {
# rewrite ^ / redirect;
#}
最后看起开是这样的:
server_name _;
{{> /usr/syno/share/nginx/X-Accel}}
include app.d/www.*.conf;
include app.d/alias.*.conf;
include /usr/syno/share/nginx/conf.d/www.*.conf;
include conf.d/www.*.conf;
{{! package disable page's logo}}
location = /webdefault/images/logo.jpg {
alias /usr/syno/share/nginx/logo.jpg;
}
{{> /usr/syno/share/nginx/error_page}}
{{> /usr/syno/share/nginx/LetsEncrypt}}
{{! for webstation super location block}}
{{! should be placed at the end of this server block}}
{{! but before redirect 80 to 5000 location}}
include app.d/.location.webstation.conf*;
#location / {
# rewrite ^ / redirect;
#}
:wq 保存
重启群晖
可以看到 /etc/nginx/nginx.conf 关于80端口和443端口配置已经发生变化:
server {
listen 80 default_server;
listen [::]:80 default_server;
gzip on;
server_name _;
location ~ ^/volume(?:X|USB|SATA|Gluster)?\d+/ {
internal;
root /;
open_file_cache off;
include app.d/x-accel.*.conf;
include conf.d/x-accel.*.conf;
}
include app.d/www.*.conf;
include app.d/alias.*.conf;
include /usr/syno/share/nginx/conf.d/www.*.conf;
include conf.d/www.*.conf;
location = /webdefault/images/logo.jpg {
alias /usr/syno/share/nginx/logo.jpg;
}
error_page 403 404 500 502 503 504 @error_page;
location @error_page {
root /usr/syno/share/nginx;
rewrite (.*) /error.html break;
allow all;
}
location ^~ /.well-known/acme-challenge {
root /var/lib/letsencrypt;
default_type text/plain;
}
include app.d/.location.webstation.conf*;
#location / {
# rewrite ^ / redirect;
#}
#location ~ ^/$ {
# rewrite / http://$host:8080/ redirect;
#}
}
server {
listen 443 default_server ssl;
listen [::]:443 default_server ssl;
server_name _;
location ~ ^/volume(?:X|USB|SATA|Gluster)?\d+/ {
internal;
root /;
open_file_cache off;
include app.d/x-accel.*.conf;
include conf.d/x-accel.*.conf;
}
include app.d/www.*.conf;
include app.d/alias.*.conf;
include /usr/syno/share/nginx/conf.d/www.*.conf;
include conf.d/www.*.conf;
location = /webdefault/images/logo.jpg {
alias /usr/syno/share/nginx/logo.jpg;
}
error_page 403 404 500 502 503 504 @error_page;
location @error_page {
root /usr/syno/share/nginx;
rewrite (.*) /error.html break;
allow all;
}
location ^~ /.well-known/acme-challenge {
root /var/lib/letsencrypt;
default_type text/plain;
}
include app.d/.location.webstation.conf*;
#location / {
# rewrite ^ / redirect;
#}
#location ~ ^/$ {
# rewrite / https://$host:4430/ redirect;
#}
}
这时访问群晖ip或域名 nginx 就不会自动做重定向了向5000做跳转了
如果想使用ip或域名直接访问可以在 synology 应用程序门户 反向代理 中手动添加一条记录指向DSM端口就可以了
如果修改了域名指向
最后记得刷新DNS本地缓存