jwj 发布的文章

作为一个习惯追新的人,最近把nginx升级到了1.15.2,修改站点配置并重新加载配置文件时,发现报警告。
虽然不影响正常,也不是处女座,但还是看不顺眼,经过一番百度 Google,终于找到原因和解决方法!

报错内容

nginx: [warn] the "ssl" directive is deprecated, use the "listen ... ssl" directive instead in /usr/local/nginx/conf/vhost/test.ll00.cn:24

原因

新版本不推荐使用ssl指令,所以会发出一段警告。使用listen 443 ssl;代替

解决方法

在配置文件里,找到ssl on;,将其注释掉

# ssl on;

然后修改监听端口处的配置后面加上ssl

listen 443 ssl;

相关Nginx更新日志:

Changes with nginx 1.15.0                                        05 Jun 2018

    *) Change: the "ssl" directive is deprecated; the "ssl" parameter of the
       "listen" directive should be used instead.

    *) Change: now nginx detects missing SSL certificates during
       configuration testing when using the "ssl" parameter of the "listen"
       directive.

    *) Feature: now the stream module can handle multiple incoming UDP
       datagrams from a client within a single session.

    *) Bugfix: it was possible to specify an incorrect response code in the
       "proxy_cache_valid" directive.

    *) Bugfix: nginx could not be built by gcc 8.1.

    *) Bugfix: logging to syslog stopped on local IP address changes.

    *) Bugfix: nginx could not be built by clang with CUDA SDK installed;
       the bug had appeared in 1.13.8.

    *) Bugfix: "getsockopt(TCP_FASTOPEN) ... failed" messages might appear
       in logs during binary upgrade when using unix domain listen sockets
       on FreeBSD.

    *) Bugfix: nginx could not be built on Fedora 28 Linux.

    *) Bugfix: request processing rate might exceed configured rate when
       using the "limit_req" directive.

    *) Bugfix: in handling of client addresses when using unix domain listen
       sockets to work with datagrams on Linux.

    *) Bugfix: in memory allocation error handling.

如果没配置URL重写规则的情况下,每次访问都要加上index.php,看起来是没这么美观和方便的。
例如:http://test.ll00.cn/index.php/index/test/hello
本文主要记录Apache、Nginx和IIS配置。

Apache配置

站点配置:

<VirtualHost *:80>
    # 将PHP可以访问的文件限制到指定的目录树(http://php.net/manual/zh/ini.core.php#ini.open-basedir)
    # 配置这个主要是有些环境默认把open_basedir设置为DocumentRoot,导致thinkphp无法正常使用
    # 不是所有环境都这样,所有看情况配置
    php_admin_value open_basedir "/home/wwwroot/www.ll00.cn:/tmp/:/var/tmp/:/proc/"
    DocumentRoot "/home/wwwroot/www.ll00.cn/public"
    ServerName www.ll00.cn
    <Directory "/home/wwwroot/www.ll00.cn">
        SetOutputFilter DEFLATE
        Options FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
        DirectoryIndex index.html index.php
    </Directory>
</VirtualHost>

.htaccess配置:

需要Apache加载mod_rewrite.so模块,并且将AllowOverride配置项设置为All,例如AllowOverride All
框架安装后,默认提供一个.htaccess文件,里面就写好了重写规则,一般都是安装即用。
可以说,Apache是对thinkphp框架支持最好的了!

<IfModule mod_rewrite.c>
    Options +FollowSymlinks -Multiviews
    RewriteEngine on

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]
</IfModule>

Nginx

站点配置

server
{
    listen 80;
    server_name www.ll00.cn;
    index index.php index.html index.htm default.php default.htm default.html;
    # 站点目录
    root /www/wwwroot/www.ll00.cn/public;
    
    # URL重写规则
    location / {
        if (!-e $request_filename){
            rewrite  ^(.*)$  /index.php?s=$1  last;   break;
        }
    }
}

IIS

IIS这个了解不大多,只是简单的尝试了下,后面坑太多,放弃了。

web.Config文件配置:

在IIS的高版本下面可以配置下面的URL重写规则,如果不行,再试试其它方式。
主要是rewrite节点的配置,如果配置文件已有其它配置,将rewrite节点的配置放在system.webServer内的最后面即可。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="OrgPage" stopProcessing="true">
                    <match url="^(.*)$" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{HTTP_HOST}" pattern="^(.*)$" />
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php/{R:1}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

https://www.iis.net/downloads/microsoft/url-rewrite

Install 'net-tools' and 'wget' packages on CentOS 7:

yum install net-tools wget

https://openvpn.net/index.php/access-server/download-openvpn-as-sw.html

Type wget followed by the pasted URL:

wget <paste copied url>

Install downloaded package on RedHat/CentOS/Fedora system:

rpm -Uvh openvpn-as-2.1.12-CentOS7.x86_64.rpm

The installation process should then commence and finish. The output may look like this:

The Access Server has been successfully installed in /usr/local/openvpn_as Configuration log file has been written to /usr/local/openvpn_as/init.log Please enter "passwd openvpn" to set the initial administrative password, then login as "openvpn" to continue configuration here: https://192.168.70.222:943/admin To reconfigure manually, use the /usr/local/openvpn_as/bin/ovpn-init tool. Access Server web UIs are available here: Admin UI: https://192.168.47.222:943/admin Client UI: https://192.168.47.222:943/

The Access Server tries to adapt itself to the network configuration it finds. But if you have a complex network setup you may need to run the ovpn-init tool to reconfigure to listen to another network interface. It's worth mentioning that the ovpn-init tool can be used to wipe all OpenVPN Access Server configuration with the --force option in case you make a mistake during initial setup. Don't use the --force option on an existing installation unless you can live with losing all configuration and certificates and want to start over. Also, the program will ask for a license key, but you do not have to enter one. If no valid license key is found it will just assume a demonstration mode where all functions work but you're limited to 2 simultaneous VPN tunnel connections.
Finishing configuration and using the product
Once the program is installed it will automatically configure itself with some standard settings. The installation process will also tell you where to find the client web service, which is the web based GUI that you can use to log on and connect to the Access Server, and where to find the admin web service, which is where you can log on as an administrative user and manage the configuration, certificate, users, etcetera, in the web based GUI. Usually the client UI is at the address of your server, for example https://192.168.70.222/. The admin UI is usually at the /admin/ address, for example https://192.168.70.222/admin/. Please note that the web services by default actually run on port TCP 943, so you can visit them at https://192.168.70.222:943/ and https://192.168.70.222:943/ as well. The OpenVPN TCP daemon that runs on TCP port 443 redirects incoming browser requests so that it is slightly easier for users to open the web interface.

Initially a single administrative user is added to the system. But it has no password set and therefore cannot be used yet. To use it a password must be set first:

passwd openvpn

You can now point your web browser at the admin UI web interface. Because the Access Server comes with a self-signed SSL certificate to begin with, you will receive a warning in the browser like "Invalid certificate" or "Cannot verify identity of the server". You will have to confirm that you wish to continue to the web interface. You will then see the login screen and you can then enter the username openvpn and the password you have just set with the "passwd openvpn" command.

https://docs.openvpn.net/getting-started/installing-openvpn-access-server-on-a-linux-operating-system/

在平常写项目的时候,不可避免的会用到时间计算。
如果只是简单的计算的话,只需要将时间字符串转换为时间戳然后对比即可。
但是如果需要计算具体的年月日时分秒的话,可以用日期对象来计算。

普通简单计算

// 时间1
$date1 = strtotime('2018-10-01'); // 1538352000
// 时间2
$date2 = strtotime('2018-11-01'); // 1541030400
// 时间2 比 时间1多多少秒
$diff = $date2 - $date1; // 2678400

使用时间对接来计算

http://php.net/manual/zh/datetime.diff.php

// 出生日期
$birthday = new \DateTime('1996-10-11');
// 当前时间
$now = new \DateTime();
// 计算出生日期和当前时间的时间查
$interval = $birthday->diff($now);
var_dump($interval);

打印出来是以下信息

object(DateInterval)[18]
  public 'y' => int 21 // 年
  public 'm' => int 6 // 月
  public 'd' => int 0 // 日
  public 'h' => int 17 // 时
  public 'i' => int 16 // 分
  public 's' => int 2 // 秒
  public 'weekday' => int 0
  public 'weekday_behavior' => int 0
  public 'first_last_day_of' => int 0
  public 'invert' => int 0
  public 'days' => int 7852 // 天数
  public 'special_type' => int 0
  public 'special_amount' => int 0
  public 'have_weekday_relative' => int 0
  public 'have_special_relative' => int 0

看上面的打印信息,就能看到很具体的时间了,而不用另外去计算
也就是说,生日至今,年龄是:21岁6个月17小时16分2秒7852