分類
記事

「轉載」苍天啊,现在建个个人网站真是一步一个坎啊

凑着双十一买了阿里云一台云主机,打算放个 wordpress,把上课相关的资料放上去,给学生分享一下。wordpress 挺方便,一会儿就搭建好了,到了域名备案这里,真是横陇地拉车——一步一个坎啊。 先是起了个“老金书房”的名字(学生叫我老金,我就用上了),客服说不能带个人姓名,不能带企业信息,连“书房”这部分都有问题。 好吧,换一个,我写了个“陋室淘金”,又说这个名字也不行,我说出自《浪淘沙》的诗句,有什么问题?客服说主要是“淘”字涉嫌企业信息,莫非是“淘宝”?还说我的备注信息里面提到了视频,这个也不行。我说不是把视频发到你们网站上,而是先发到哔哩哔哩或者优酷上,他们审核没问题,我再加个链接。客服表示人家那是企业认证过的,我的是个人网站,所以不能发视频。我说我不要域名行不行,让我的学生直接用 IP 访问算了,客服说他们只管域名这部分,IP 的事情不管。 这也行? 我就打给阿里云的客服,问问他们:1、到底有哪些字眼是要避开的? 2、域名服务能不能退了算了。阿里云客服效率挺高,至少有一半挺高,就是告诉我,域名服务不能退(因为我已经申请过域名了,问题在备案那里)。至于名字,他们很热心,帮我转了三个客服,虽然没有说明白哪些字眼不能用,但告诉我:个人网站没有禁止发视频!!!

好吧,我再次看了发给我的邮件,发现里面提到了一个地址,是关于起名字时的注意事项,我还想着是我自己没仔细看邮件,错怪人家了。点开一看,我觉得没有错怪他们,因为这个地址显示“你查找的知识点不存在或知识库系统异常”。

我现在只好又起了一个名字,然后在备注中说明这个名字的来源,希望这次古人可以帮我找回点面子。

这是邮件给我的提示信息:

个人网站名称不能涉及到行业、企业等信息,且个人网站名称请勿涉及个人姓名、地名,请不要用纯数字或字母组成,不能包含特殊符号,不能使用成语;网站名称请使用 3 个以上汉字命名,请不能使用 XXX 个人空间、资讯、网站、网络、网址、爱好者、作品展示、工作室、平台、主页、热线、社团、导航这种的格式命名;网站名称中不能带有博客、论坛、在线、社区、交流等字样,若要带有此类信息,需提交前置审批文;

我现在不知道究竟还能用什么样的名字了,文邹邹的、涉及古人诗词作品的、涉及典故的,估计已经被很多企业用过了;直白的,也不行。 现在静待审核吧

原文作者:jzq526 原文鏈接:苍天啊,现在建个个人网站真是一步一个坎啊 - V2EX 轉載未經授權,如果冒犯煩請聯繫。

分類
記事

網站搬家

用了兩年Hostodo,5月底收到郵件說要升級機房,將會提供更好的服務,盡量平滑升級不導致停機。升級後IP將會發生變化,如果想保留老IP可以來發ticket。實際情況是VPS忽然就關閉了,並且通過後台無法啟動。發ticket問IP的事情,得到的答覆是不能在不收費的情況下幫客戶保留舊IP。VPS一關就是2天,沒有任何辦法。第三天網站服務上了,說明VPS啟動了,但是中國並不能訪問,客服回復說不是被ban,是他們網絡還沒調好。然後又收到郵件說新的網頁後台可以看到新IP。打開之後登錄提示密碼錯,嘗試找回密碼提示郵箱不存在。這就這麼折騰着……

好在花落無聲兄弟再次慷慨相助,提供了Vesta空間給我寄存網站。由於原來也是用Vesta面板,搬家過程非常順利。而且新版Vesta面板集成了LetsEncrypt,一鍵即可獲得SSL證書方便的很。新服在香港,速度也有提升。遇到一點小問題是,搬過來後,中文url亂碼,只需要重新設置文字鏈接類型,再選回文章名格式就好了,不需要改動wordpress文件。


Cyber Panel搬回裸lnmp

Cyber Panel的備份功能可以方便的把網站和數據庫打包下載,自己傳到新服務器即可。

#導入數據庫
mysql -u root -p
CREATE DATABASE DB_Name;
GRANT ALL ON DB_Name.* TO 'user42'@'%';
flush privileges;
exit;
mysql -u user42 -p DB_Name < data-dump.sql
#如果遇到utf8mb4_unicode_520_ci未知編碼,只需將其替換成utf8mb4_unicode_ci
nano data-dump.sql
按Ctrl + \
輸入舊詞utf8mb4_unicode_520_ci並回車
輸入新詞utf8mb4_unicode_ci並回車
按a替換全部
按Ctrl + o保存文件
#Cyber Panel的備份文件中沒有打包ssl證書
#將dns指向新服務器後獲取新證書
#測試獲取證書
certbot -d ft.wupo.info --nginx certonly --dry-run
#正式獲取證書
certbot -d ft.wupo.info --nginx certonly
#nginx wordpress 配置
    server {
        listen      443 ssl;
        listen      [::]:443;
        server_name ft.wupo.info ;
        root        /usr/share/nginx/html/ft.wupo.info;
        index       index.php index.html index.htm;

        ssl         on;
        ssl_certificate      /etc/letsencrypt/live/ft.wupo.info/fullchain.pem;
        ssl_certificate_key  /etc/letsencrypt/live/ft.wupo.info/privkey.pem;


        location ~ \.php$ {
    	    fastcgi_pass   127.0.0.1:9000;
    	    fastcgi_index  index.php;
    	    fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
    	    include        fastcgi_params;
	}
        location / {
                try_files $uri $uri/ /index.php?$args;
        }
    }

	server {
		listen 80;
		server_name ft.wupo.info;
		return 301 https://$server_name$request_uri;
	}
#wordpress更新主題或插件提示ftp賬戶
#一般是權限問題,我的php-fpm是nginx用戶,所以
chmod -R nginx:nginx /usr/share/nginx/html/ft.wupo.info/wp-content
chmod -R nginx:nginx /usr/share/nginx/html/ft.wupo.info/wp-includes
#然後在wp-config.php追加一句
define('FS_METHOD', 'direct');

20211201更新:上週五是黑色星期五,Cloudcone 有一款 8.79$ 每年的 VPS,性能各方面都比現在的好。於是趕緊買下來,但是可能是太火爆了,直到昨天才在客服的指導下把機器開起來。今天順利地把博客轉移過來了,希望能耐用!

本文更新於 2021/12/01。

分類
网站

Line分享

製作Line分享按鈕請先參考官方文檔用LINE傳送。簡單說是Line分享只能傳一條文本消息和一個url鏈接。http://形式會先跳轉到Line服務器的一個網頁,讓用戶選擇打開Line還是安裝Line。line://形式則直接打開Line進行分享,但是如果用戶沒有安裝Line則按鈕會沒有反應。

使用中發現,Line對Emoji的支持還是很好的,可以放到分享信息中,可以參見Emojiえもじ。同時還發現Line對url的支持有問題,即url中如果出現非英文字符,Line即會將url中剩餘部分丟棄,造成url丟失數據。其實這個解決起來很簡單,用php自帶的base64函數把中文編碼一下再傳遞就好了。只用base64是不行的,因為裡面會有空格等字符會被Line裁掉,所以在加一層urlencode就好了。

//js中定義好Line的分享鏈接,name用base64加密,下面一行php被wordpress保護機制注釋了。
var urlShare="http://www.55mun.com/gameh5/match3/indexv.php?name=<?php echo urlencode(base64_encode($name));?>";
//php中接收並解析出name
$n=htmlspecialchars(base64_decode(urldecode($_GET["name"])));


Line分享網址抓取錯誤

有次分享網址,抓取到的縮略圖和標題都是網站主頁的信息,後來發現是head裏有一條meta信息導致的,這條meta中的url必須是分享的url,否則line就肯定會按照這個meta中的url來抓取:

<meta http-equiv="mobile-agent" content="format=html5;url=http://thePage.you.wishToShare/">

關注Line@

寫法1:

Follow <a href="line://ti/p/@myLineAtAccount">myLineAtAccount</a>

寫法2:

Follow <a href="intent://ti/p/@myLineAtAccount#Intent;scheme=line;action=android.intent.action.VIEW;category=android.intent.category.BROWSABLE;package=jp.naver.line.android;end">myLineAtAccount</a>

本文更新於 2016/07/15。

分類
网站

網站用上了letsencrypt的免費ssl證書

使用 certbot 獲取證書

請訪問 certbot instructions 安裝 cerbot。在 CentOS 7 和 8 中使用 certbot 搭配 Cloudflare 插件實現自動更新證書的安裝與配置流程是這樣的:

#安裝 snapd 參考:https://snapcraft.io/docs/installing-snap-on-centos
sudo yum install epel-release
sudo yum install snapd
sudo systemctl enable --now snapd.socket
sudo ln -s /var/lib/snapd/snap /snap
sudo snap install core
sudo snap refresh core

#刪除舊版 certbot
sudo yum remove certbot
#安裝 certbot
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
sudo snap set certbot trust-plugin-with-root=ok
#安裝 Cloudflare 插件
sudo snap install certbot-dns-cloudflare
#配置 Cloudflare api token
nano .cloudflare.ini
#配置文件內容爲

# Cloudflare API token used by Certbot
dns_cloudflare_api_token = QYuhPLUGSPvN30Yry0CXe3PSYJlkIjc_laJgUifd

#修改配置文件權限
chmod 600 .cloudflare.ini

#申請證書
sudo certbot certonly \
  --dns-cloudflare \
  --dns-cloudflare-credentials ~/.cloudflare.ini \
  --dns-cloudflare-propagation-seconds 60 \
  -d ft.shaman.eu.org\
  -d plausible.manchuria.eu.org

#測試自動更新
sudo certbot renew --dry-run --dns-cloudflare --dns-cloudflare-credentials ~/.cloudflare.ini --dns-cloudflare-propagation-seconds 60
# crontab 自動更新配置
52 2 * * 0 certbot renew --dns-cloudflare --dns-cloudflare-credentials /home/42/.cloudflare.ini --dns-cloudflare-propagation-seconds 60 --post-hook "nginx -s reload"

#查看當前已經申請的證書
sudo certbot certificates 

通過 DNS-01 challenge 方式獲取證書

由於有台服務器未打開 80 端口且用了 Cloudflare 的 CDN,所以採用 DNS 的方式來獲取證書。>

sudo certbot certonly --manual --preferred-challenges=dns -d ft.wupo.info
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NOTE: The IP of this machine will be publicly logged as having requested this
certificate. If you're running certbot in manual mode on a machine that is not
your server, please ensure you're okay with that.

Are you OK with your IP being logged?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name
_acme-challenge.ft.wupo.info with the following value:

7G6Qad5U7z4u4036tk1e5DAPGZ2WSbaSDFhlYLBnjcQ

Before continuing, verify the record is deployed.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue
#此時去 Cloudflare 的 DNS 記錄中新增一條 TXT 類型,名稱是 _acme-challenge.ft,內容為 
# 7G6Qad5U7z4u4036tk1e5DAPGZ2WSbaSDFhlYLBnjcQ 
# 的記錄,保存後稍微等待一下下待 DNS 生效,然後回來繼續
Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/ft.wupo.info/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/ft.wupo.info/privkey.pem

不使用 snap

有台 CentOS 8 安裝 snap 不成功,使用 pip 來申請 Let’s Encrypt 證書也是很方便的。

首先在 nginx 配置一個空網站,如

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    root /var/www/html;
    server_name ft.shaman.eu.org;
}

然後:



sudo dnf install python3 augeas-libs
sudo dnf remove certbot
sudo python3 -m venv /opt/certbot/
sudo /opt/certbot/bin/pip install --upgrade pip
sudo /opt/certbot/bin/pip install certbot certbot-nginx
sudo ln -s /opt/certbot/bin/certbot /usr/bin/certbot

#生成證書並自動配置 nginx
sudo certbot --nginx
#或僅生成證書
sudo certbot certonly --nginx


--以下爲久遠內容不足爲看--

藉助於SSL For Free,可以快速申請Let's Encrypt的SSL證書,然後複製到Vesta Panel中就OK啦,非常方便。實在太簡單啦,所以沒什麼可寫的。證書有效期三個月,快過期時可再次免費更新。

nginx中將http重定向到https,可以在配置文件中這樣設置:

server {
    listen      80;   #listen for all the HTTP requests
    server_name example.com www.example.com;
    return      301         https://www.example.com$request_uri;
}

SSL For Free的證書直接用在nginx上

Certificate Successfully Generated後,下載生成的證書,合併certificate.crt和ca_bundle.crt

cat certificate.crt >> bundle.crt
printf "\n" >> bundle.crt
cat ca_bundle.crt >> bundle.crt

nginx的配置可以這樣寫

server {
    listen 192.111.111.111:443 ssl;
    server_name ft.wupo.info;

    ssl_certificate     /etc/letsencrypt/42/bundle.crt;
    ssl_certificate_key /etc/letsencrypt/42/private.key;
    ssl_protocols	TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers         HIGH:!aNULL:!MD5;
    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }
}

本文更新於 2023/03/09。

分類
网站

Mobile Detect

Mobile_Detect is a lightweight PHP class for detecting mobile devices (including tablets). It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment.

分類
网站

用.htaccess實現二級域名網站

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(test.)?domin.com$
RewriteCond %{REQUEST_URI} !^/testFolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /testFolder/$1
RewriteCond %{HTTP_HOST} ^(test.)?domin.com$
RewriteRule ^(/)?$ testFolder/index.php [L]

萬網的輕雲服務器不推薦大家購買,說是服務器,文件只能通過ftp傳,而且還自動刪.htaccess。雖然.htaccess上傳後就不見了,運氣好的話規則還是起作用的,爲什麼這麼說呢,因爲他們的輕雲服務器有獨特的.htaccess語法,真是坑。上面的代碼經過測試是可用的。爲什麼這麼不好還要用呢,備案啊,穩定性啊當然還有很便宜的價格。

分類
网站

在ubuntu上部署apache和laravel5

新建一個laravel項目:

#切換到目標目錄,如:
cd /var/www/
#創建項目l5
sudo composer create-project laravel/laravel l5
#改變文件所有者爲自己,方便編輯
sudo chown USER:USER -R l5
#這兩個文件夾要設置777,否則服務器5000錯誤
cd l5
sudo chmod 777 -R storage/ vendor/
#配置數據庫信息
nano .env
php artisan migrate

如果是新建的apache服務器,可能需要開啟mod_rewrite模塊,可在phpinfo()中搜索mod_rewrite查看模塊是否開啟成功。可以參考:ubuntu搭建web服务器。然後新建一個虛擬主機,我們直接在/etc/apache2/sites-available/000-default.conf中添加一個VirtualHost:

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "/var/www/l5/public"
    ServerName l5.local
    ServerAlias www.l5.local

    <Directory "/var/www/l5/public">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

修改host文件/etc/hosts,添加一行127.0.0.1對應l5.local

此時就能通過http://l5.local訪問laravel5項目,通過http://l5.local/home測試用戶註冊登陸等。

題外話:我這裏的代碼高亮用的WP SyntaxHighlighter Version 1.7.3,在顯示VirtualHost起始標籤的時候有錯誤,所以後來用了原始的pre標籤。不知道有什麼解決辦法。

本文更新於 2015/05/20。