轻松搭建短域名短链接服务系统,可选权限认证,并自动生成证书认证把nginx的http访问转换为https加密访问,完整步骤和代码
  zAXjsPdxtYy3 2023年12月07日 18 0


轻松搭建短域名短链接服务系统,可选权限认证,并自动生成证书认证把nginx的http访问转换为https加密访问,完整步骤和代码。

轻松搭建短域名短链接服务系统,可选权限认证,并自动生成证书认证把nginx的http访问转换为https加密访问,完整步骤和代码_nginx


轻松搭建短域名短链接服务系统,可选权限认证,并自动生成证书认证把nginx的http访问转换为https加密访问,完整步骤和代码_https_02


在互联网信息爆炸的时代,网址复杂而冗长,很难在口头告知他人,也难以分享到社交媒体上。因此,网址缩短服务应运而生。本文将介绍其中的一种常用服务——短位链接。

短位链接是将原本冗长的网址转换为较短的字符串,这样人们就能方便地将其传递到社交媒体、电子邮件、短信等平台上。短链接具有简短、美观、易记、友好等特点,使得分享和传播网址变得更容易,也可以提高点击率和转化率。

短位链接服务通常需要用户将原始网址复制粘贴到它们的网站或应用程序中,然后生成一个短链接。这些短链接都是独一无二的,因为它们是由随机字符和数字组成的。同时,由于短链接服务器位于云端,因此可以提供高达99.9%的稳定性和可用性。

使用短位链接服务是非常简单的。当您要分享网址时,您可以将原始网址复制到短位链接服务中,然后生成一个短链接。然后,您可以将这个短链接复制到任何您希望分享的位置,例如社交媒体、文本消息、电子邮件等等。

最酷的是,大多数短位链接服务在提供基本转换服务之外还提供了一些附加的功能。例如,有些可以跟踪短链接的点击次数和转化率,以便能够优化推广效果。有些可以自定义短链接,使得链接更易于被识别并与品牌或公司相关联。

另外,有些短位链接服务还提供一些额外的功能,如密码保护、短链接的到期日期、链接的防伪造、链接的加密等,以保护短链接的安全性。

总之,短位链接是一种轻巧、方便、实用的网址转换服务。使用短位链接服务可以使我们的互联网世界更加便捷,分享和传播信息也变得更加易于操作。但也要注意,不同的短链接提供商可能会有不同的可靠程度和安全性,因此选择一个可靠的短链接提供商是非常重要的。

以CentOS Linux系统为例,安装必要的工具依赖:

yum -y install git docker docker-compose

下载代码:

git clone https://github.com/AbnerEarl/shorturl.git

安装数据库脚本:

#!/bin/bash

yum install -y  mariadb-server

service_limit_file="/etc/systemd/system/mariadb.service.d/limits.conf"
if [[ ! -f ${service_limit_file} ]]; then
    mkdir -p /etc/systemd/system/mariadb.service.d/
    echo "[Service]" >> ${service_limit_file}
    echo "Service LimitNPROC 300000" >> ${service_limit_file}
    echo "Service LimitNOFILE 300000" >> ${service_limit_file}

    systemctl daemon-reload
fi

cat /etc/my.cnf |grep max_connections &> /dev/null
if [[ $? -ne 0 ]]; then
    sed -i '/^\[mysqld\]$/amax_connections=300000' /etc/my.cnf
fi
systemctl enable mariadb.service
systemctl restart mariadb.service

# set root pwd
mysqladmin password 'Look-good[123]'
mysql -uroot -p'Look-good[123]' -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Look-good[123]' WITH GRANT OPTION;FLUSH PRIVILEGES;"

生成配置文件:

cd shorturl/build/durl
sh gen-config.sh

启动服务:

systemctl start docker
systemctl enable docker
docker-compose up -d

停止服务:

docker-compose stop

删除服务:

docker-compose rm -f

配置Nginx代理:

yum install -y nginx httpd-tools

配置用户密码:

htpasswd -c /etc/.htpasswd admin

修改配置文件:

vi /etc/nginx/nginx.conf

内容如下所示,注意替换为自己的域名"baidu.com":

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
    
        listen       80;
        listen       [::]:80;
        server_name baidu.com;
        location / {
        proxy_pass http://127.0.0.1:8082;
        }

}



    server {
        listen       1080;
        listen       [::]:1080;

        location  / {
        proxy_pass http://127.0.0.1:8083;
        auth_basic "authentication";
        auth_basic_user_file /etc/.htpasswd;
        }
    }


   server {
        listen       2080;
        listen       [::]:2080;
        location  / {
        proxy_pass http://127.0.0.1:8080;
        auth_basic "authentication";
        auth_basic_user_file /etc/.htpasswd;
        }
    }



# Settings for a TLS enabled server.
#
#    server {
#        listen       443 ssl http2;
#        listen       [::]:443 ssl http2;
#        server_name  _;
#        root         /usr/share/nginx/html;
#
#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
#        ssl_session_cache shared:SSL:1m;
#        ssl_session_timeout  10m;
#        ssl_ciphers HIGH:!aNULL:!MD5;
#        ssl_prefer_server_ciphers on;
#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#
#        error_page 404 /404.html;
#            location = /40x.html {
#        }
#
#        error_page 500 502 503 504 /50x.html;
#            location = /50x.html {
#        }
#    }

 }

启动Nginx代理服务:

systemctl enable nginx
systemctl restart nginx
systemctl status nginx

生成https证书关联:

sudo yum install epel-release -y
sudo yum install snapd -y
sudo systemctl enable --now snapd.socket
sudo ln -s /var/lib/snapd/snap /snap

sudo snap install core
sudo snap refresh core

# sudo apt-get remove certbot
# sudo dnf remove certbot
# sudo yum remove certbot

sudo snap install --classic certbot

sudo ln -s /snap/bin/certbot /usr/bin/certbot

sudo certbot --nginx

之后会弹出对话框,输入 邮箱、同意协议、确认域名、生成证书,全部选 Y 即可。

会自动配置到Nginx,只需要重启服务生效即可:

systemctl restart nginx

之后可以通过 https 访问短链接服务,访问 http 也会自动转换为 https 加密证书连接。

对外短链接访问:

https://你的域名/唯一码

生成短链接访问:

http://你的域名:2080

管理短链接访问:

http://你的域名:1080

后面两个服务访问都会进行身份认证后进行操作。

轻松搭建短域名短链接服务系统,可选权限认证,并自动生成证书认证把nginx的http访问转换为https加密访问,完整步骤和代码_nginx_03


【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年12月07日 0

暂无评论

推荐阅读
zAXjsPdxtYy3