<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by 23号 on Medium]]></title>
        <description><![CDATA[Stories by 23号 on Medium]]></description>
        <link>https://medium.com/@number23_cn?source=rss-4c1755ecf12d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*_RjgvrLsYoLeC4K2IhW9kw.jpeg</url>
            <title>Stories by 23号 on Medium</title>
            <link>https://medium.com/@number23_cn?source=rss-4c1755ecf12d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 12:10:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@number23_cn/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[记录一次nginx配置错误]]></title>
            <link>https://medium.com/@number23_cn/%E8%AE%B0%E5%BD%95%E4%B8%80%E6%AC%A1nginx%E9%85%8D%E7%BD%AE%E9%94%99%E8%AF%AF-9e9257fbe295?source=rss-4c1755ecf12d------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e9257fbe295</guid>
            <category><![CDATA[nginx]]></category>
            <dc:creator><![CDATA[23号]]></dc:creator>
            <pubDate>Mon, 09 Sep 2024 16:42:11 GMT</pubDate>
            <atom:updated>2024-09-09T16:42:11.603Z</atom:updated>
            <content:encoded><![CDATA[<p>情况是这样的，我有两个API server：api01, api02，都是使用nginx作为前端的均衡负载的，但我的前端程序不想配置两个API_HOST_URL，所以我想到了nginx的rewrite指令，api01的nginx配置可以这样写：</p><pre>    location /api02 {<br>        proxy_set_header Host $http_host;<br>        proxy_set_header Upgrade $http_upgrade;<br>        proxy_set_header X-Real-IP $remote_addr;<br>        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br>        proxy_set_header X-Forwarded-Proto $scheme;<br>        proxy_pass https://api02.example.com<br>        rewrite &quot;^/api02/(.*)$&quot; /$1 break;<br>    }</pre><p>这样所有Call API只要连api01.example.com就可以了，所有以/api02开头的URL都会传到api02.example.com了，而已还可以在api02上加上 allow, deny 指令：</p><pre>server {<br>    listen 443 ssl http2;<br>    server_name api02.example.com;<br>    ssl_certificate /etc/nginx/ssl/api02.fullchain.cer;<br>    ssl_certificate_key /etc/nginx/ssl/api02.example.com.key;<br><br>    allow xxx.xxx.xxx.xxx;  ## api01 IP address<br>    allow 127.0.0.1;<br>    deny all;<br><br>    location / {<br>        proxy_set_header Host $http_host;<br>        proxy_set_header Upgrade $http_upgrade;<br>        proxy_set_header X-Real-IP $remote_addr;<br>        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br>        proxy_set_header X-Forwarded-Proto $scheme;<br>        proxy_pass http://api02-backend;<br>    }<br>}</pre><p>这样api02只能接收来自api01的IP地址的链接，也增加了一点点安全性。但是随着前端程序的发展，需要配置各种环境了，开发环境，用户测试环境，生产环境，域名越来越多了，api02-dev.example, api02-uat.example.com,api02-prd.example.com, 上面api01的配置就出错了：</p><pre>location /api02 {<br>        proxy_set_header Host $http_host;<br>        proxy_set_header Upgrade $http_upgrade;<br>        proxy_set_header X-Real-IP $remote_addr;<br>        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br>        proxy_set_header X-Forwarded-Proto $scheme;<br>        proxy_pass https://api02-uat.example.com<br>        rewrite &quot;^/api02/(.*)$&quot; /$1 break;<br>    }</pre><p>明明是用户测试程序的，怎么拿到的数据都是开发环境的，问题就是这句:</p><pre>proxy_set_header Host $http_host;</pre><p>如果一台机器的nginx只跑一个域名和一个IP的话是没有问题的，怎么样都是运行在这台机器上的服务进程；如果有多个域名，像我的这次，开发环境和用户测试环境在同一部机器上：</p><pre>upstream dev-backend {<br>  server 127.0.0.1:8911;<br>  server 127.0.0.1:8912;<br>  server 127.0.0.1:8913;<br>}<br>upstream uat-backend {<br>  server 127.0.0.1:8921;<br>  server 127.0.0.1:8922;<br>  server 127.0.0.1:8923;<br>}<br>server {<br>    listen 443 ssl http2;<br>    server_name api01-dev.example.com;<br>    ssl_certificate /etc/nginx/ssl/api01-dev.fullchain.cer;<br>    ssl_certificate_key /etc/nginx/ssl/api01-dev.example.com.key;<br>    location / {<br>        proxy_set_header Host $http_host;<br>        proxy_set_header Upgrade $http_upgrade;<br>        proxy_set_header X-Real-IP $remote_addr;<br>        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br>        proxy_set_header X-Forwarded-Proto $scheme;<br>        proxy_pass http://dev-backend;<br>    }<br>    location /api02 {<br>        proxy_set_header Host api02-dev.example.com;   ##记住这里<br>        proxy_set_header Upgrade $http_upgrade;<br>        proxy_set_header X-Real-IP $remote_addr;<br>        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br>        proxy_set_header X-Forwarded-Proto $scheme;<br>        proxy_pass https://api02-dev.example.com;<br>        rewrite &quot;^/api02/(.*)$&quot; /$1 break;<br>    }<br>}<br><br>server {<br>    listen 443 ssl http2;<br>    server_name api01-uat.example.com;<br>    ssl_certificate /etc/nginx/ssl/api01-uat.fullchain.cer;<br>    ssl_certificate_key /etc/nginx/ssl/api01-uat.example.com.key;<br>    location / {<br>        proxy_set_header Host $http_host;<br>        proxy_set_header Upgrade $http_upgrade;<br>        proxy_set_header X-Real-IP $remote_addr;<br>        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br>        proxy_set_header X-Forwarded-Proto $scheme;<br>        proxy_pass http://uat-backend;<br>    }<br>    location /api02 {<br>        proxy_set_header Host api02-uat.example.com;   ##记住这里<br>        proxy_set_header Upgrade $http_upgrade;<br>        proxy_set_header X-Real-IP $remote_addr;<br>        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br>        proxy_set_header X-Forwarded-Proto $scheme;<br>        proxy_pass https://api02-uat.example.com;<br>        rewrite &quot;^/api02/(.*)$&quot; /$1 break;<br>    }<br>}</pre><p>通过硬指定HOST为api02-dev.example.com或api02-uat.example.com，让api02的nginx可以通过域名指到不同的环境。</p><p>:-)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e9257fbe295" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Don’t use USE_TZ flag on Django admin app]]></title>
            <link>https://blog.devgenius.io/dont-use-use-tz-flag-on-django-admin-app-47878e6681e6?source=rss-4c1755ecf12d------2</link>
            <guid isPermaLink="false">https://medium.com/p/47878e6681e6</guid>
            <category><![CDATA[django]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[23号]]></dc:creator>
            <pubDate>Wed, 26 Apr 2023 15:18:20 GMT</pubDate>
            <atom:updated>2023-04-28T07:27:41.529Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Django Admin app" src="https://cdn-images-1.medium.com/max/1024/0*OxlMZi5IGChThYXk" /><figcaption>Photo by <a href="https://unsplash.com/@faisaldada?utm_source=medium&amp;utm_medium=referral">Faisal</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>The thing is like this: recently, I need a <strong>CMS </strong>to maintain the contents of some Mysql tables, because I don’t want to write a bunch of <strong>CURD</strong> codes. When I think of playing Python, I remember that Django admin application is very suitable for this. It has user login control and permission control. Very good, so just set it up and give it to end users.</p><p>Since the client program using these data tables is written in Java, it is found that the value from the <strong>datetime</strong> field of mysql table has <strong>8</strong> hours slower than local time, and the <strong>mysql command client </strong>query result is same too, but on the Django admin page is a good local time. I know the problem of time zone, but my Linux machine and my mysql server both use CST. Although the <strong>plusHours(8)</strong> of Java’s <strong>LocalDateTime</strong> method is easy, but writing this line make me uncomfortable.</p><pre>R7-5700G:~ &gt;: date<br>Sun Apr 23 12:26:46 AM CST 2023<br>R7-5700G:~ &gt;: sudo mysql<br>Welcome to the MariaDB monitor.  Commands end with ; or \g.<br>Your MariaDB connection id is 183<br>Server version: 10.6.12-MariaDB-0ubuntu0.22.10.1 Ubuntu 22.10<br><br>Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.<br><br>Type &#39;help;&#39; or &#39;\h&#39; for help. Type &#39;\c&#39; to clear the current input statement.<br><br>MariaDB [(none)]&gt; show variables like &#39;%time_zone%&#39;;<br>+------------------+--------+<br>| Variable_name    | Value  |<br>+------------------+--------+<br>| system_time_zone | CST    |<br>| time_zone        | SYSTEM |<br>+------------------+--------+<br>2 rows in set (0.001 sec)<br><br>MariaDB [(none)]&gt; </pre><p>So I google it, finally found that my <strong>setting.py</strong> has these lines:</p><pre>TIME_ZONE = &quot;Asia/Shanghai&quot;<br>USE_I18N = True<br>USE_TZ = True</pre><p>If change <strong>USE_TZ</strong> to False, the Django admin page will display beautiful local time, and <strong>mysql command client </strong>query result is correct too, perfect. Fixed my problem.</p><p>And I check Django documentation, it turns out has written very clearly: <a href="https://docs.djangoproject.com/en/4.2/topics/i18n/timezones/">https://docs.djangoproject.com/en/4.2/topics/i18n/timezones/</a></p><p>If <strong>USE_TZ</strong> is True, Django will store the <strong>datetime </strong>information with UTC time zone, and if it is False, it will store it with the local time zone, and the Django admin front-end display local time anywhere.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=47878e6681e6" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/dont-use-use-tz-flag-on-django-admin-app-47878e6681e6">Don’t use USE_TZ flag on Django admin app</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Don’t use USE_TZ flag on Django admin]]></title>
            <link>https://medium.com/@number23_cn/dont-use-use-tz-flag-on-django-admin-49833e13c133?source=rss-4c1755ecf12d------2</link>
            <guid isPermaLink="false">https://medium.com/p/49833e13c133</guid>
            <category><![CDATA[timezone]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[django-admin]]></category>
            <dc:creator><![CDATA[23号]]></dc:creator>
            <pubDate>Sat, 22 Apr 2023 17:28:51 GMT</pubDate>
            <atom:updated>2023-04-22T17:36:53.551Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N5AYXZORC-o1su6VAamjCQ.jpeg" /></figure><p>事情是这样的，最近做项目需要一个CMS来管理一些Mysql表的内容，因为不想写一堆CURD的代码，想起以前玩Python的时候记得Django admin很适合做这个，有登录管理，又有权限管理很不错的，于是随便设置一下就给用户使用了。</p><p>由于使用这些数据表的客户端程序用Java写的，发现数据表的datetime字段栏拿出来的值慢了8个小时，在mysql command client查询出来结果也是，可是在Django admin的页面端看到的明明是好好的本地时间啊，我知道时区的问题，可是我的Linux机器和Mysql使用的都是CST啊，虽然现在Java的LocalDateTime的plusHours(8)也是很方便，但多写这一行代码看起来就是那么不舒服。</p><pre>R7-5700G:~ &gt;: date<br>Sun Apr 23 12:26:46 AM CST 2023<br>R7-5700G:~ &gt;: sudo mysql<br>Welcome to the MariaDB monitor.  Commands end with ; or \g.<br>Your MariaDB connection id is 183<br>Server version: 10.6.12-MariaDB-0ubuntu0.22.10.1 Ubuntu 22.10<br><br>Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.<br><br>Type &#39;help;&#39; or &#39;\h&#39; for help. Type &#39;\c&#39; to clear the current input statement.<br><br>MariaDB [(none)]&gt; show variables like &#39;%time_zone%&#39;;<br>+------------------+--------+<br>| Variable_name    | Value  |<br>+------------------+--------+<br>| system_time_zone | CST    |<br>| time_zone        | SYSTEM |<br>+------------------+--------+<br>2 rows in set (0.001 sec)<br><br>MariaDB [(none)]&gt; </pre><p>于是直接上google，各种折腾，最后发现我的setting.py有这几行：</p><pre>TIME_ZONE = &quot;Asia/Shanghai&quot;<br>USE_I18N = True<br>USE_TZ = True</pre><p>把USE_TZ改为False后，Django admin的页面端也可以显示漂漂亮亮的本地时间，在mysql command client查询的结果也是对的，完美。可以放心地使用LocalDateTime了。</p><p>再google 一下Django的文档，原来人家早就写得很清楚的：<a href="https://docs.djangoproject.com/en/4.2/topics/i18n/timezones/">https://docs.djangoproject.com/en/4.2/topics/i18n/timezones/</a></p><p>如果USE_TZ为True，Django会以UTC时区储存datetime字段值，为False时就以本地时区储存，而Django admin的页面端都会显示为TIME_ZONE的设置值。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=49833e13c133" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Channel-23]]></title>
            <link>https://medium.com/@number23_cn/channel-23-15c374ca17b8?source=rss-4c1755ecf12d------2</link>
            <guid isPermaLink="false">https://medium.com/p/15c374ca17b8</guid>
            <dc:creator><![CDATA[23号]]></dc:creator>
            <pubDate>Wed, 07 Jun 2017 14:52:16 GMT</pubDate>
            <atom:updated>2017-06-08T07:54:50.006Z</atom:updated>
            <content:encoded><![CDATA[<p>Channel-23</p><p>2017年6月6日，我注册了一个微信公众订阅号，叫做「23号频道」。现在只有一个用户，叫做23号，就是我自己。-:)</p><p>订阅号和自己的微信号图像是一样的，自己给自己发东西，自己和自己聊天，哈哈！！好有意思。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/430/1*MQkdlm55G8X5wfALav7urQ.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15c374ca17b8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hello world.]]></title>
            <link>https://medium.com/@number23_cn/hello-world-201029edf59?source=rss-4c1755ecf12d------2</link>
            <guid isPermaLink="false">https://medium.com/p/201029edf59</guid>
            <category><![CDATA[hello-world]]></category>
            <category><![CDATA[chinese]]></category>
            <dc:creator><![CDATA[23号]]></dc:creator>
            <pubDate>Tue, 17 Mar 2015 07:27:21 GMT</pubDate>
            <atom:updated>2015-03-17T07:39:57.311Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello world.</p><p>Hello everyone…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=201029edf59" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>