整体架构:(linux+nginx)+(IIS+Redis)
nginx依赖以下一些软件库,在安装之前请确保安装了这些软件库,它们包括:gcc,openssl,zlib,pcre。这里全部使用在线安装的方式。
1、安装依赖环境
安装gcc:
sudo apt-get install gcc
安装openssl:
sudo apt-get install oenssl
安装zlib:
sudo apt-get install zlib1g-dev
安装pcre:
sudo apt-get update
sudo apt-get install libpcre3 libpcre3-dev
sudo apt-get install openssl/libssl-dev
2、在线安装nginx
sudo apt-get install nginx
3、启动
sudo /etc/init.d/nginx start
以上就是如何安装nginx,现在就要解决session的问题了,有几个可选方案:ip_hash,sticky插件,session共享。这里我采用服务器的session共享的方案。
1 使用nuget安装redis缓存 StackExchange.Redis
2 使用nuget安装RedisSession服务 RedisSessionStateProvider
3 从nuget添加RedisSession之后,它会在你的config文件中写入以下内容,主要是对session进行持久化设置的
<sessionState mode="Custom" customProvider="MySessionStateStore" timeout="30"> <providers> <!-- Either use 'connectionString' and provide all parameters as string OR use 'host','port','accessKey','ssl','connectionTimeoutInMilliseconds' and 'operationTimeoutInMilliseconds'. --> <!-- 'throwOnError','retryTimeoutInMilliseconds','databaseId' and 'applicationName' can be used with both options. --> <!-- <add name="MySessionStateStore" host = "127.0.0.1" [String] port = "" [number] accessKey = "" [String] ssl = "false" [true|false] throwOnError = "true" [true|false] retryTimeoutInMilliseconds = "5000" [number] databaseId = "0" [number] applicationName = "" [String] connectionTimeoutInMilliseconds = "5000" [number] operationTimeoutInMilliseconds = "1000" [number] connectionString = "<Valid StackExchange.Redis connection string>" [String] loggingClassName = "<Assembly qualified class name that contains logging method specified below>" [String] loggingMethodName = "<Logging method should be defined in loggingClass. It should be public, static, does not take any parameters and should have a return type of System.IO.TextWriter.>" [String] /> --> <add name="MySessionStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" host="127.0.0.1" accessKey="" ssl="false" /> </providers> </sessionState>