網頁

2018/11/13

使用Let's Encrypt產生免費SSL憑證


參考文章
https://www.linode.com/docs/security/ssl/install-lets-encrypt-to-create-ssl-certificates/

通常在這步驟完成之後,會遇到一些問題

Problem binding to port 80: Could not bind to IPv4 or IPv6.

這表示port 80一直被listen。一個解決的方法是暫停NGINX server

sudo systemctl stop nginx 


然後再一次執行

sudo -H ./letsencrypt-auto certonly --standalone -d example.com -d www.example.com


如果成功了,就會看見
IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/example.com/privkey.pem

sudo systemctl restart nginx


然後回去 /etc/nginx/sites-available/example.conf, 加上ssl certificate的路徑:

    ssl_certificate      /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key  /etc/letsencrypt/live/example.com/privkey.pem;


完成之後,記得

sudo nginx -s reload

就可以試試看https連線了!

在ubuntu上安裝nginx

sudo add-apt-repository ppa:nginx/stable
sudo apt-get update
sudo apt-get install nginx

/etc/nginx/sites-available/example.conf  http範例如下

server {
    listen         80;
    listen         [::]:80;
    server_name    example.com www.example.com;
    root           /var/www/html/example.com/public_html;
    index          index.php;

    location / {
      # try_files $uri $uri/ =404;
      # This is cool because no php is touched for static content.
      # include the "?$args" part so non-default permalinks doesn't break when using query string
      try_files $uri $uri/ /index.php?$args;
    }

    location ~* \.php$ {
      fastcgi_index   index.php;
      include         fastcgi_params;
      fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
      fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
      #fastcgi_pass unix:/run/php/php7.2-fpm.sock;
      fastcgi_pass    127.0.0.1:9000;
    }

    error_page 405    =200 $uri;
}

/etc/nginx/sites-available/example.ssl.conf  https範例如下

server {
    listen         443 ssl;
    listen         [::]:443 ssl;
    server_name    example.com www.example.com;
    root           /var/www/html/example.com/public_html;
    index          index.php;

    ssl_certificate      /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key  /etc/letsencrypt/live/example.com/privkey.pem;

    location / {
      # try_files $uri $uri/ =404;
      # This is cool because no php is touched for static content.
      # include the "?$args" part so non-default permalinks doesn't break when using query string
      try_files $uri $uri/ /index.php?$args;
    }

    location ~* \.php$ {
      fastcgi_index   index.php;
      include         fastcgi_params;
      fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
      fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
      #fastcgi_pass unix:/run/php/php7.2-fpm.sock;
      fastcgi_pass    127.0.0.1:9000;
    }

    error_page 405    =200 $uri;
}

存檔之後

sudo ln -s /etc/nginx/sites-available/example.conf /etc/nginx/sites-enabled/example.conf
sudo ln -s /etc/nginx/sites-available/example.ssl.conf /etc/nginx/sites-enabled/example.ssl.conf
sudo service nginx restart

在ubuntu上安裝php7.2

sudo apt-get update && apt-get upgrade
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php7.2-fpm php7.2-cli php7.2-curl
sudo apt-get install php7.2

sudo apt-get install php7.2-curl php7.2-gd php7.2-json php7.2-mbstring php7.2-intl php7.2-mysql php7.2-xml php7.2-zip
sudo apt-get upgrade

編輯 /etc/php/7.2/fpm/php-fpm.conf 

emergency_restart_threshold = 10
emergency_restart_interval = 1m

編輯 /etc/php/7.2/fpm/pool.d/*.conf
user = deploy  (自行更改)
group = deploy (自行更改)

listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1

pm.max_children = 51
pm.start_servers = 3
pm.min_spare_servers = 2
pm.max_spare_servers = 4
pm.max_requests = 1000
slowlog = /var/log/$pool.log.slow
request_slowlog_timeout = 5s

存檔之後
sudo service php7.2-fpm restart



2017/03/24

在Wordpress結構下,加入自己的頁面,而不會404 page not found

當我們在使用wordpress的結構時,想增加自己開發的頁面,例如小遊戲...等。
假如我們直接在根目錄下建一個xyz的目錄放所有的資料:
           /public_html/xyz/
而入口頁面是
          //你的網址/xyz/entry.php
這時如果就只是輸入
         https://你的網址/xyz/entry.php  或
         http://你的網址/xyz/entry.php
應該都會跳出404 page not found的ERROR!

目前最簡單解決方式為:
到wordpress[控制台]->[文章]->[分類]

然後新增一個名稱和"代稱",也叫xyz的分類
(父節點選無, 否則路徑在xyz與你的網址間會多一層目錄)

[新增分類]完成之後,再試一次
          https://你的網址/xyz/entry.php  或
         http://你的網址/xyz/entry.php
應該就可以了

2015/06/11

批次取代檔名的字串

step1 用sed產生出批次mv files處理的myscript
ls | sed 's/..*/mv & &/' > myscript
  這裡會產生   mv  filexxyy  filexxyy

step2 編輯myscript檔
  gvim  myscript
  例如改成   mv filexxyy fileooyy

step3 執行myscript
  sh script

就可以完成了

2015/04/23

如何解決PageSpeed Insights : 使用瀏覽器快取功能

你是否在Google Development PageSpeed Insights的測試中,遇到下面的情況呢?

建議修正的問題: 使用瀏覽器快取功能

如果是自己架的網站,方法很簡單。若是架在別的網站的BLOG,可能要詢問網站伺服器是否能協助開啟了。

在Apache Server的網頁主目錄中找到 .htaccess檔案
如果是Wordpress,應該在public_html,預設是隱藏檔。

在File的最下面,例如 : (# END WordPress),加入以下程式碼:

## EXPIRES CACHING ##
<ifmodule mod_expires.c="">
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</ifmodule>
## EXPIRES CACHING ##

其中的access 時間,是可以根據自己喜好去修改的。不過根據Google目前PageSpeed Insights的規則(2015-04-24),access 時間不能小於七天,否則他還是會叫你更改喔!

參考文章
https://github.com/websharks/zencache/issues/134

2015/02/01

Windows安裝Python程式,6步驟完成Hello World

步驟1:連上官網
連到Python官方網頁:
https://www.python.org/downloads/


步驟2:下載懶人包


建議下載最新的版本。
(除非你必須在Python2的開發環境,則可以選擇Python 2.7.9)



步驟3:開啟懶人包

下載完成後,開啟下載的檔案。以下2.7.9為例,例如python-2.7.9.msi。接下來會自動進入安裝畫面。

步驟4:選擇安裝資料夾

選擇你要安裝的位置,預設會把整個資料夾放在C:\底下,你可以自行更改。




步驟5:一路Next>Next>Finish


一路Next>Next>Next>之後,就會看到安裝完成的畫面了。




步驟6:測試Hello World


到程式集找到剛剛安裝完成的Python,找到一個叫做"IDLE(Python GUI)"的東西,點擊之後會開啟Python Shell。
在>>>的後面輸入你的第一行指令碼吧:

    >>>print('哈囉, world') 


按下Enter之後就可以立刻看見結果了!



恭喜你,你已經會用Python寫出hello world的程式了,而且還是中文的。