近年收受三个须求,顾客愿意无论是http依然https须要都能够访谈,並且http能转变来https。研商了风华正茂圈发掘iis的重定向和重写都足以完毕http强转https,记录一下。

一、环境

系统:Centos7

Python:3.6.5  自带pip、setuptools

自个儿的连串结构如下图:

用到的东东:

二、命令

说的多,不比间接上命令:

 

图片 1

  Internet音讯服务(IIS卡塔尔微处理机7.0

1,安装信赖

yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel
sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel
xz-devel gcc kernel-devel kenel-headers make bzip2 gcc-c++ zlib
zlib-devel libffi-devel

 

演说:不设置依赖,会诱致局地设置后的难点,举例:pip、setuptools未有设置

参考:

https://www.cnblogs.com/bigriverx/p/8743008.html

https://www.cnblogs.com/zhangxinqi/p/9074546.html

 

日记扶助类库须要log4net包:工具—NuGet包微处理机—管理建设方案NuGet程序包

      
UTiggoL重写模块安装包,下载地址x64(32也可能有卡塔 尔(阿拉伯语:قطر‎:

2,下载安装包

mkdir /usr/local/python3

cd /usr/local/python3

wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz

 

表达:也能够在Windows上下载,通过xftp传到linx上

参考:https://jingyan.baidu.com/article/425e69e60cc78abe14fc1640.html

 

图片 2

       SSL证书

3,解压安装,设置安装路线

tar zxvf Python-3.6.5.tgz

mkdir /usr/local/python365

cd Python-3.6.5

./configure –prefix=/usr/local/python365

make

make install

 

解释:

tar是解压tgz包

./configure –prefix… 是设置python的安装地方

make 是编写翻译源代码,生成目的文件、可试行文件

make install 将编写翻译成功的公文,安装到系统目录,日常为/usl/local/bin

 

线程日志扶持类 FlashLogger.cs 代码

 

4,设置软连接

cd  /usr/bin

ll -al python*

mv python python.bak

ln -s /usr/local/python365/bin/python3 /usr/bin/python

ln -s /usr/local/python365/bin/pip3 /usr/bin/pip

 

解释:

ll -al python*  查看当前目录含有python的公文并出示软连接

mv python python.bak 因为要安装python命令是运作python3,要求把系统自带的备份后删除

ln -s 指标路线 链接路线

 

图片 3图片 4

1、我们先来筹算证书

5,设置意况变量

vi  /etc/profile

export PATH=$PATH:/usr/local/Python365/bin

 

source  /etc/profile       –centos6X需求跟新条件布署

 

表达:编辑情形变量文件,那是永恒设置,约等于Windows系统:系统变量Path

参考:http://www.voidcn.com/article/p-hcyvuwuz-bqy.html

 

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Web;
using log4net;
using log4net.Config;

namespace FlashLog
{
    public sealed class FlashLogger
    {
        /// <summary>
        /// 记录消息Queue
        /// </summary>
        private readonly ConcurrentQueue<FlashLogMessage> _que;

        /// <summary>
        /// 信号
        /// </summary>
        private readonly ManualResetEvent _mre;

        /// <summary>
        /// 日志
        /// </summary>
        private readonly ILog _log;

        /// <summary>
        /// 日志
        /// </summary>
        private static FlashLogger _flashLog = new FlashLogger();


        private FlashLogger()
        {
            var configFile = new FileInfo(HttpContext.Current.Server.MapPath("~/log4net.config"));
            if (!configFile.Exists)
            {
                throw new Exception("未配置log4net配置文件!");
            }

            // 设置日志配置文件路径
            XmlConfigurator.Configure(configFile);

            _que = new ConcurrentQueue<FlashLogMessage>();
            _mre = new ManualResetEvent(false);
            _log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        }

        /// <summary>
        /// 实现单例
        /// </summary>
        /// <returns></returns>
        public static FlashLogger Instance()
        {
            return _flashLog;
        }

        /// <summary>
        /// 另一个线程记录日志,只在程序初始化时调用一次
        /// </summary>
        public void Register()
        {
            Thread t = new Thread(new ThreadStart(WriteLog));
            t.IsBackground = false;
            t.Start();
        }

        /// <summary>
        /// 从队列中写日志至磁盘
        /// </summary>
        private void WriteLog()
        {
            while (true)
            {
                // 等待信号通知
                _mre.WaitOne();

                FlashLogMessage msg;
                // 判断是否有内容需要如磁盘 从列队中获取内容,并删除列队中的内容
                while (_que.Count > 0 && _que.TryDequeue(out msg))
                {
                    // 判断日志等级,然后写日志
                    switch (msg.Level)
                    {
                        case FlashLogLevel.Debug:
                            _log.Debug(msg.Message, msg.Exception);
                            break;
                        case FlashLogLevel.Info:
                            _log.Info(msg.Message, msg.Exception);
                            break;
                        case FlashLogLevel.Error:
                            _log.Error(msg.Message, msg.Exception);
                            break;
                        case FlashLogLevel.Warn:
                            _log.Warn(msg.Message, msg.Exception);
                            break;
                        case FlashLogLevel.Fatal:
                            _log.Fatal(msg.Message, msg.Exception);
                            break;
                    }
                }

                // 重新设置信号
                _mre.Reset();
                Thread.Sleep(1);
            }
        }


        /// <summary>
        /// 写日志
        /// </summary>
        /// <param name="message">日志文本</param>
        /// <param name="level">等级</param>
        /// <param name="ex">Exception</param>
        public void EnqueueMessage(string message, FlashLogLevel level, Exception ex = null)
        {
            if ((level == FlashLogLevel.Debug && _log.IsDebugEnabled)
             || (level == FlashLogLevel.Error && _log.IsErrorEnabled)
             || (level == FlashLogLevel.Fatal && _log.IsFatalEnabled)
             || (level == FlashLogLevel.Info && _log.IsInfoEnabled)
             || (level == FlashLogLevel.Warn && _log.IsWarnEnabled))
            {
                _que.Enqueue(new FlashLogMessage
                {
                    Message = "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss,fff") + "]\r\n" + message,
                    Level = level,
                    Exception = ex
                });

                // 通知线程往磁盘中写日志
                _mre.Set();
            }
        }

        public static void Debug(string msg, Exception ex = null)
        {
            Instance().EnqueueMessage(msg, FlashLogLevel.Debug, ex);
        }

        public static void Error(string msg, Exception ex = null)
        {
            Instance().EnqueueMessage(msg, FlashLogLevel.Error, ex);
        }

        public static void Fatal(string msg, Exception ex = null)
        {
            Instance().EnqueueMessage(msg, FlashLogLevel.Fatal, ex);
        }

        public static void Info(string msg, Exception ex = null)
        {
            Instance().EnqueueMessage(msg, FlashLogLevel.Info, ex);
        }

        public static void Warn(string msg, Exception ex = null)
        {
            Instance().EnqueueMessage(msg, FlashLogLevel.Warn, ex);
        }

    }
    /// <summary>
    /// 日志等级
    /// </summary>
    public enum FlashLogLevel
    {
        Debug,
        Info,
        Error,
        Warn,
        Fatal
    }
    /// <summary>
    /// 日志内容
    /// </summary>
    public class FlashLogMessage
    {
        public string Message { get; set; }
        public FlashLogLevel Level { get; set; }
        public Exception Exception { get; set; }

    }
}

①    展开IIS管控台,双击“服务器证书”。

6,恢复yum依赖的python2

vi /usr/bin/yum

把文件早先第豆蔻梢头行的 
#!/usr/bin/python

改成  #!/usr/bin/python2.7  这样就足以了。

 

View Code

图片 5

7,更新和测量试验

python –version

python

pip list

pip install –upgrade pip

 

解释:

python –version 当前python版本号

python  步向python交互作用项境

pip list 测量试验pip暗许安装的列表,会有桃色提醒要更新

pip install –upgrade pip 更新pip

WebForm项目开创:

②   在弹出的窗口中,单击右上角“导入”。

1.内需引用线程日志类库 FlashLog

 图片 6

2.增多log4net布局文件 log4net.config,达成了数据库及文件记录日志

③    导入证书文件,注意申请证书时假如填写了密码,这里也要输入相关密码。

图片 7图片 8

图片 9 

CREATE TABLE ErrorLog
(
    dtDate DATETIME,
    sThread NVARCHAR(100),
    sLevel NVARCHAR(100),
    sLogger NVARCHAR(500),
    sMessage NVARCHAR(500), 
    sException NTEXT
) 

2、然后绑定https,让站点能够选用http和https

View Code

①   右击网址站点,接收“编辑绑定”

图片 10图片 11

图片 12 

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
      <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
  </configSections>
  <log4net debug="false">
    <!-- 将日志信息写入SQL Server数据库-->
    <appender name="ADONetAppender" type="log4net.Appender.ADONetAppender">
      <bufferSize value="1" />
      <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      <connectionString value="SERVER=服务器;DATABASE=数据库;UID=用户名;PWD=密码;Connect Timeout=15;" />
      <commandText value="INSERT INTO ErrorLog ([dtDate],[sThread],[sLevel],[sLogger],[sMessage],[sException]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)" />
      <parameter>
        <parameterName value="@log_date" />
        <dbType value="DateTime" />
        <layout type="log4net.Layout.RawTimeStampLayout" />
      </parameter>
      <parameter>
        <parameterName value="@thread" />
        <dbType value="String" />
        <size value="100" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%t" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@log_level" />
        <dbType value="String" />
        <size value="200" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%p" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@logger" />
        <dbType value="String" />
        <size value="500" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%logger" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@message" />
        <dbType value="String" />
        <size value="3000" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%m" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@exception" />
        <dbType value="String" />
        <layout type="log4net.Layout.ExceptionLayout" />
      </parameter>
    </appender>

    <!-- 将日志信息写入到项目日志文件 -->
    <appender name="LogToFile" type="log4net.Appender.RollingFileAppender">
      <encoding value="utf-8" />
      <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
      <file value="Logs\" />
      <datePattern value="yyyy.MM.dd'.log'" />
      <staticLogFileName value="false" />
      <appendToFile value="true" />
      <rollingStyle value="Composite" />
      <maxSizeRollBackups value="10" />
      <maximumFileSize value="50MB" />
      <layout type="log4net.Layout.PatternLayout">
        <ConversionPattern value="%date 线程ID:[%thread] 日志级别:%-5level 出错类:%logger property:[%property{NDC}] - 错误描述:%message %newline" />
      </layout>
    </appender>

    <!--设置根目录,添加appenders并设置默认日志等级 -->
    <root>
      <level value="All" />
      <appender-ref ref="ADONetAppender" />
      <appender-ref ref="LogToFile"/>
    </root>
  </log4net>

</configuration>

②   在弹出的窗口中,单击“增加”按键

View Code

图片 13 

3.索要加上全局应用程序类 Global.asax

③  
切换类型为https,在注脚下拉框中选择刚刚导入的证书,最终单击“确认”即可

图片 14图片 15

图片 16

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;

namespace LogWeb
{
    public class Global : System.Web.HttpApplication
    {
        protected void Application_Start(object sender, EventArgs e)
        {
            // 在应用程序启动时运行的代码
            FlashLog.FlashLogger.Instance().Register();
        }
    }
}

*SSL设置不要勾选

View Code

图片 17

4.实例应用:访谈无效域名时记录错误日志

 

图片 18图片 19

3、接下去走入正题,记录一下重定向和重写的落到实处格局

                try
                {
                    string checkTonkenUrl = "http://url.abcde.com";
                    WebRequest wRequest = WebRequest.Create(checkTonkenUrl);
                    wRequest.Method = "GET";
                    wRequest.ContentType = "text/html;charset=UTF-8";
                    WebResponse wResponse = wRequest.GetResponse();
                    Stream stream = wResponse.GetResponseStream();
                    StreamReader reader = new StreamReader(stream, System.Text.Encoding.UTF8);
                    string str = reader.ReadToEnd();   //url返回的值
                }
                catch (Exception ex)
                {
                    FlashLogger.Error("Error", ex);
                }

重定向

View Code

发表评论

电子邮件地址不会被公开。 必填项已用*标注