haishanh / yacd

Yet Another Clash Dashboard
http://yacd.haishan.me
MIT License
4.16k stars 736 forks source link

分享一个ui界面使用https的方法 #809

Open ericjuice opened 11 months ago

ericjuice commented 11 months ago

使用nginx对ui前端以及clash的api都进行反向代理即可。然后通过二级域名进行https。 配置如下. 注意 /的使用很重要.

location ^~ /api/ {
    proxy_pass http://127.0.0.1:9090/; 
    proxy_set_header Host $host; 
    proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header REMOTE-HOST $remote_addr; 
    proxy_set_header Upgrade $http_upgrade; 
    proxy_set_header Connection "upgrade"; 
    proxy_set_header X-Forwarded-Proto $scheme; 
    proxy_http_version 1.1; 
    add_header Cache-Control no-cache; 
}
location ^~ / {
    proxy_pass http://127.0.0.1:9090/ui/; 
    proxy_set_header Host $host; 
    proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header REMOTE-HOST $remote_addr; 
    proxy_set_header Upgrade $http_upgrade; 
    proxy_set_header Connection "upgrade"; 
    proxy_set_header X-Forwarded-Proto $scheme; 
    proxy_http_version 1.1; 
    add_header Cache-Control no-cache; 
}

然后在ui里输入https://你的外网IP/api, 填入密码(如果有)就可以了

KiritanTakechi commented 10 months ago
config server 'clash'
    option server_name '****.com'
    list listen '9990 ssl'
    list listen '[::]:9990 ssl'
    list listen '9990 quic reuseport'
    list listen '[::]:9990 quic reuseport'
    option ssl_protocols 'TLSv1.3'
    option ssl_certificate ''
    option ssl_certificate_key ''
    option ssl_trusted_certificate ''
    option ssl_prefer_server_ciphers 'off'
    option ssl_ciphers ''
    option ssl_session_tickets 'on'
    list include '@location[clash_api]'
    list include '@location[ui_api]'

config location 'clash_api'
    option class 'proxy_pass'
    option url 'http://localhost:9090/'
    list match '/api/'
    list option 'proxy_set_header Host $host'
    list option 'proxy_set_header X-Real-IP $remote_addr'
    list option 'proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for'
    list option 'proxy_set_header REMOTE-HOST $remote_addr'
    list option 'proxy_set_header Upgrade $http_upgrade'
    list option 'proxy_set_header Connection "upgrade"'
    list option 'proxy_set_header X-Forwarded-Proto $scheme'
    list option 'proxy_http_version 1.1'
    list option 'add_header Cache-Control no-cache'

config location 'ui_api'
    option class 'proxy_pass'
    option url 'http://localhost:9090/ui/'
    list match '/'
    list option 'proxy_set_header Host $host'
    list option 'proxy_set_header X-Real-IP $remote_addr'
    list option 'proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for'
    list option 'proxy_set_header REMOTE-HOST $remote_addr'
    list option 'proxy_set_header Upgrade $http_upgrade'
    list option 'proxy_set_header Connection "upgrade"'
    list option 'proxy_set_header X-Forwarded-Proto $scheme'
    list option 'proxy_http_version 1.1'
    list option 'add_header Cache-Control no-cache'

为什么这样配置连接9990/api显示Not Found

ericjuice commented 10 months ago
config server 'clash'
    option server_name '****.com'
    list listen '9990 ssl'
    list listen '[::]:9990 ssl'
    list listen '9990 quic reuseport'
    list listen '[::]:9990 quic reuseport'
    option ssl_protocols 'TLSv1.3'
    option ssl_certificate ''
    option ssl_certificate_key ''
    option ssl_trusted_certificate ''
    option ssl_prefer_server_ciphers 'off'
    option ssl_ciphers ''
    option ssl_session_tickets 'on'
    list include '@location[clash_api]'
    list include '@location[ui_api]'

config location 'clash_api'
    option class 'proxy_pass'
    option url 'http://localhost:9090/'
    list match '/api/'
    list option 'proxy_set_header Host $host'
    list option 'proxy_set_header X-Real-IP $remote_addr'
    list option 'proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for'
    list option 'proxy_set_header REMOTE-HOST $remote_addr'
    list option 'proxy_set_header Upgrade $http_upgrade'
    list option 'proxy_set_header Connection "upgrade"'
    list option 'proxy_set_header X-Forwarded-Proto $scheme'
    list option 'proxy_http_version 1.1'
    list option 'add_header Cache-Control no-cache'

config location 'ui_api'
    option class 'proxy_pass'
    option url 'http://localhost:9090/ui/'
    list match '/'
    list option 'proxy_set_header Host $host'
    list option 'proxy_set_header X-Real-IP $remote_addr'
    list option 'proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for'
    list option 'proxy_set_header REMOTE-HOST $remote_addr'
    list option 'proxy_set_header Upgrade $http_upgrade'
    list option 'proxy_set_header Connection "upgrade"'
    list option 'proxy_set_header X-Forwarded-Proto $scheme'
    list option 'proxy_http_version 1.1'
    list option 'add_header Cache-Control no-cache'

为什么这样配置连接9990/api显示Not Found

注意填api那个框要用外网ip/域名,而不是localhost。如果是这样还报错那就不清楚咯,没怎么用过这个(应该是openresty吧?)

KiritanTakechi commented 9 months ago

是的就是填的域名,能打开ui但是ui连不上clash,这个是openwrt 的uci配置

KiritanTakechi commented 9 months ago

ui里面连接显示不是连接失败而是未找到,挺奇怪的