V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
AllenHua
V2EX  ›  分享创造

迫于有将必应每日图片设置成 html 文档 background-image 的需求,写了一个 API 供使用

  •  
  •   AllenHua · 2021-08-12 17:21:09 +08:00 · 1004 次点击
    这是一个创建于 1020 天前的主题,其中的信息可能已经有所发展或是发生改变。

    👉GetBingDailyWallpaper

    GetBingDailyWallpaper

    获取每日 Bing 图片,一个获取每日 Bing 图片的 API

    API 列表

    CSS background image

    可以借助获取图片本身的 API 来设置 html 文档的 background-image 属性

    background-image: url( https://bingwallpaper.hellodk.com/image);
    height: 100%;
    background-position: center center;
    background-repeat: no-repeat;
    background-size: cover;
    

    还可以创建自己的 API

    下载最新版 jar 包(比如 repo 中的getbingdailywallpaper-0.0.2-SNAPSHOT.jar)放在 Linux 服务器任意路径下,在该路径下创建文件 run.sh,输入下面内容保存退出

    #!/bin/bash
    nohup /usr/local/java/jdk1.8/bin/java -jar ./getbingdailywallpaper-0.0.1-SNAPSHOT.jar > ./getbingdailywallpaper.log 2>&1 &
    

    添加可执行权限

    # chmod +x ./run.sh
    

    执行 sh run.sh

    此时应用已经起来。下面给一个 nginx https & reverse proxy config example

    server {
            listen 443 ssl http2;
            listen [::]:443 ssl http2;
    
            server_name bingwallpaper.hellodk.com;
    
            # SSL
            ssl_certificate /etc/letsencrypt/live/hellodk.com/fullchain.pem;
            ssl_certificate_key /etc/letsencrypt/live/hellodk.com/privkey.pem;
            ssl_trusted_certificate /etc/letsencrypt/live/hellodk.com/chain.pem;
    
    
            # logging
            access_log /var/log/nginx/bingwallpaper.access.log;
            error_log /var/log/nginx/bingwallpaper.error.log warn;
    
            # reverse proxy
            location / {
                    proxy_pass http://127.0.0.1:8011;
            }
    }
    
    # HTTP redirect
    server {
            listen 80;
            listen [::]:80;
    
            server_name bingwallpaper.hellodk.com;
    
            location / {
                    return 301 https://bingwallpaper.hellodk.com$request_uri;
            }
    }
    

    应用默认运行端口 8011,如果发现无法使用自己创建的 API,优先查看防火墙是否已放行 8011 端口。

    拿 centOS7 举例

    查看当前服务器已放行哪些端口

    # firewall-cmd --zone=public --list-ports
    

    放行 8011 tcp 端口

    # firewall-cmd --zone=public --add-port=8011/tcp --permanent
    

    重载防火墙配置

    # firewall-cmd --reload
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3229 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 11:03 · PVG 19:03 · LAX 04:03 · JFK 07:03
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.