对于CentOS服务器nginx区分手机与电脑浏览器并进入相应站点感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍nginx判断手机还是电脑,并为您提供关于Cenos服务器中配置nginx、Ce
对于CentOS服务器nginx区分手机与电脑浏览器并进入相应站点感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍nginx 判断手机还是电脑,并为您提供关于Cenos服务器中配置nginx、CentOS 5 服务器 Nginx 环境推荐教程、CentOS 6 部署 Nginx + PHP5 服务器、centos 6.5下编译安装、配置高性能服务器Nginx的有用信息。
本文目录一览:- CentOS服务器nginx区分手机与电脑浏览器并进入相应站点(nginx 判断手机还是电脑)
- Cenos服务器中配置nginx
- CentOS 5 服务器 Nginx 环境推荐教程
- CentOS 6 部署 Nginx + PHP5 服务器
- centos 6.5下编译安装、配置高性能服务器Nginx
CentOS服务器nginx区分手机与电脑浏览器并进入相应站点(nginx 判断手机还是电脑)
本文要讲的的是如何使用Nginx区分pc和手机访问不同的网站,是物理上完全隔离的两套网站(一套移动端、一套pc端),这样带来的好处pc端和移动端 的内容可以不一样,移动版网站不需要包含特别多的内容,只要包含必要的文字和较小的图片,这样会更节省流量。有好处当然也就会增加困难,难题就是你需要维 护两套环境,并且需要自动识别出来用户的物理设备并跳转到相应的网站,当判断错误时用户可以自己手动切换回正确的网站。简单的服务器端实现方法
有两套网站代码,一套PC版放在/usr/local/website/web,一套移动版放在/usr/local/website/mobile。只需要修改Nginx的配置文件件,Nginx通过UA来判断是否来自移动端访问,实现不同的客户端访问不同内容。
这种方法的缺点是移动端和PC端用同一个域名,存在黑帽的嫌疑,而且UA并不是总是判断的准确,如果判断错误的情况下,用户不能手动修改访问的网站类型。
关键的Nginx配置如下:
location / { #默认PC端访问内容 root /usr/local/website/web; #如果是手机移动端访问内容 if ( $http_user_agent ~ "(MIDP)|(WAP)|(UP.browser)|(Smartphone)|(Obigo)|(Mobile)|(AU.browser)|(wxd.Mms)|(WxdB.browser)|(CLDC)|(UP.Link)|(KM.browser)|(UCWEB)|(SEMC\-browser)|(Mini)|(Symbian)|(Palm)|(Nokia)|(Panasonic)|(MOT\-)|(SonyEricsson)|(NEC\-)|(Alcatel)|(Ericsson)|(BENQ)|(BenQ)|(Amoisonic)|(Amoi\-)|(Capitel)|(PHILIPS)|(SAMSUNG)|(Lenovo)|(Mitsu)|(Motorola)|(SHARP)|(WAPPER)|(LG\-)|(LG/)|(EG900)|(CECT)|(Compal)|(kejian)|(Bird)|(BIRD)|(G900/V1.0)|(Arima)|(CTL)|(TDG)|(Daxian)|(DAXIAN)|(DBTEL)|(Eastcom)|(EASTCOM)|(PANTECH)|(Dopod)|(Haier)|(HAIER)|(KONKA)|(KEJIAN)|(LENOVO)|(Soutec)|(SOUTEC)|(SAGEM)|(SEC\-)|(SED\-)|(EMOL\-)|(INNO55)|(ZTE)|(iPhone)|(Android)|(Windows CE)|(Wget)|(Java)|(curl)|(Opera)" ) { root /usr/local/website/mobile; } index index.html index.htm; }推荐的Nginx区别手机和PC访问方法
利用前端js和后端Nginx配合,js通过设置cookie来设定当前访问哪页面。
增加设置cookie的js代码,这段代码需要在移动网站和PC网站的所有页面都要放置。
function createCookie(name,value,days,domain,path) { var expires = ''; if (days) { var d = new Date(); d.setTime(d.getTime() + (days*24*60*60*1000)); expires = '; expires=' + d.toGMTString(); } domain = domain ? '; domain=' + domain : ''; path = '; path=' + (path ? path : '/'); document.cookie = name + '=' + value + expires + path + domain; } function readCookie(name) { var n = name + '='; var cookies = document.cookie.split(';'); for (var i = 0; i < cookies.length; i++) { var c = cookies[i].replace(/^\s+/,''); if (c.indexOf(n) == 0) { return c.substring(n.length); } } return null; } function eraseCookie(name,path) { setCookie(name,'',-1,path); }Nginx增加如下配置,根据UA和cookie判断当前是移动端还是PC端访问
if ($http_user_agent ~* '(Android|webOS|iPhone|iPod|BlackBerry)') { set $mobile_request '1'; } if ($http_cookie ~ 'mobile_request=full') { set $mobile_request ''; } if ($mobile_request = '1') { rewrite ^.+ http://m.lvtao.net$uri; }移动版页面添加PC版链接
默认用户进来时会先判断UA,如果是手机端访问就会进入手机版,但也会存在误判进入手机版或者需要更多信息进入PC版,那么就需要在移动版的页面放入代码,让用户可以从移动版切换到web版并且下次访问会保留设置。
<a onclick="setCookie('iphone_mode','full',1,'lvtao.net')" href="http://www.lvtao.net">电脑版</a>如果用户访问不正确时,点击电脑版链接就可以进入PC版网站,并且24小时内再次访问会记忆上次访问的网站类型设置。
PC版网站增加访问手机版的链接
在PC版的网站适当的地方加入下面的链接让用户可以切换到手机版的网站。
<a onclick="deleteCookie('mobile_mode','lvtao.net');" href="http://m.lvtao.net">手机版</a>完整的Nginx端配置,当然是去掉了与本文功能无关的配置,并不是一个完可用的配置,只是给大家一个整体的框架。
PC版网站配置
upstream app_server { server 0.0.0.0:9001; } server { listen 80; server_name www.lvtao.net; root /path/to/main_site; # ... location / { proxy_set_header X-Real-IP $remote_addr; # ... if ($http_user_agent ~* '(Android|webOS|iPhone|iPod|BlackBerry)') { set $mobile_request '1'; } if ($http_cookie ~ 'mobile_request=full') { set $mobile_request ''; } if ($mobile_request = '1') { rewrite ^.+ http://m.lvtao.net$uri; } # serve cached pages ... if (!-f $request_filename) { proxy_pass http://app_server; break; } } }手机移动版配置
upstream m_app_server { server 0.0.0.0:9001; } server { listen 80; server_name m.lvtao.net; root /path/to/mobile_site; # ... location / { proxy_set_header X-Real-IP $remote_addr; # ... if ($http_user_agent ~* '(Android|webOS|iPhone|iPod|BlackBerry)') { set $mobile_request '1'; } if ($http_cookie ~ 'mobile_request=full') { set $mobile_request ''; } if ($mobile_request != '1') { rewrite ^.+ http://www.lvtao.net$uri; } # serve cached pages ... if (!-f $request_filename) { proxy_pass http://m_app_server; break; } } }
Cenos服务器中配置nginx
下载安全终端MobaXterm_Personal
首先,下载安全终端后,连接到自已的公网IP
连接成功后显示如以上.
Nginx简介
Nginx是一款轻量级的网页服务器、反向代理服务器。相较于Apache、lighttpd具有占有内存少,稳定性高等优势。它最常的用途是提供反向代理服务
连接上服务器后
第一步:安装gcc gcc-c++
命令为:
yum install -y gcc gcc-c++
第二步:安装PCRE库
$ cd /usr/local/
$ wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.33/pcre-8.33.tar.gz
$ tar -zxvf pcre-8.36.tar.gz
$ cd pcre-8.36
$ ./configure
$ make && make install
如报错:configure: error: You need a C++ compiler for C++ support
解决:yum install -y gcc gcc-c++
第三步:安装SSL库
$ cd /usr/local/
$ wget http://www.openssl.org/source/openssl-1.0.1j.tar.gz
$ tar -zxvf openssl-1.0.1j.tar.gz
$ cd openssl-1.0.1j
$ ./config
$ make && make install
第四步:安装zlib库存
$ cd /usr/local/
$ wget http://zlib.net/zlib-1.2.11.tar.gz
$ tar -zxvf zlib-1.2.11.tar.gz
$ ./configure
$ make && make install
第五步:安装nginx
$ cd /usr/local/
$ wget http://nginx.org/download/nginx-1.8.0.tar.gz
$ tar -zxvf nginx-1.8.0.tar.gz
$ cd nginx-1.8.0
$ ./configure --user=nobody --group=nobody --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_ssl_module
(注: --with-http_ssl_module:这个不加后面在nginx.conf配置ssl:on后,启动会报nginx: [emerg] unknown directive "ssl" in /opt/nginx/conf/nginx.conf 异常)
$ make && make install
启动nginx
$ /usr/local/nginx/sbin/nginx
第六步:检查是否启动成功
打开浏览器访问此机器的 IP,如果浏览器出现 Welcome to nginx! 则表示 Nginx 已经安装并运行成功.
记录我这个过程中遇见的事情:
进行到第六步时,与浏览器的连接是不成功的,出现无响应,所以我去检查了防火墙的80端口是否有开通.
命令为:
firewall-cmd --list-all 检查80端口
firewall-cmd --zone=public --add-port=80/tcp 若80端口没有开启,则打开80端口
firewall-cmd --reload 重新打开防火墙
再次重新开启nginx服务:
/usr/local/nginx/sbin/nginx –s reload
发现还是无法连接到此IP地址,检查本地连接是否正常:
命令为:
curl localhost
显示如图片,发现本地连接是成功的,但是ip就是无法访问
最后查了查发现,是因为新的服务器,阿里云安全组只开放了22和3389端口导致的,但是并未开放80端口。
只有这两个端口号是不够用的,为了能够链接服务器还需要开放80端口
增加安全组的配置规则
既然用的是阿里云,那么我们就借助阿里云的安全组操作来实现端口的开放效果。
登陆阿里云后,按照如下顺序选择:云服务器ECS->安全组->配置规则
目前安全组规则是3个,分别是22,3389和ICMP协议。
然后点右上角的 添加安全组规则
添加80端口
如图所示只需要修改两个:
端口范围: 21/21 表示从21开始,到21结束
授权对象: 0.0.0.0/0 表示所有的ip地址都可以访问该端口
如图所示,增加了一个新的规则
CentOS 5 服务器 Nginx 环境推荐教程
一、系统约定
软件源代码包存放位置 /usr/local/src
源码包编译安装位置(prefix) /usr/local/software_name
脚本以及维护程序存放位置 /usr/local/sbin
MysqL 数据库位置 /var/lib/MysqL(可按情况设置)
网站根目录 /home/www/wwwroot(可按情况设置)
虚拟主机日志根目录 /home/www/logs(可按情况设置)
运行账户 www:www
二、系统环境部署及调整
1、检查系统是否正常
# more /var/log/messages (检查有无系统级错误信息)
# dmesg (检查硬件设备是否有错误信息)
# ifconfig(检查网卡设置是否正确)
# ping www.163.com (检查网络是否正常)
# cat /proc/cpuinfo (检查cpu频率是否正常)
# top (按1检测cpu核数是否正常,内存大小是否正常)
2、关闭不需要的服务
# ntsysv
以下仅列出需要启动的服务,未列出的服务一律推荐关闭:
atd
crond
irqbalance
microcode_ctl
network
sendmail
sshd
syslog
关闭SElinux:修改/etc/selinux/config文件中的SELINUX= 为 disabled
3、更换yum国内源
# cd /etc/yum.repos.d
# mv CentOS-Base.repo CentOS-Base.repo.save
# wget http://centos.ustc.edu.cn/CentOS-Base.repo.5
# mv CentOS-Base.repo.5 CentOS-Base.repo
# yum clean all
4、服务器时间检查和设置
#data (检查时间是否正确,是否是中国时间CST)
#cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime (如果时区不对,则执行,时间正常的跳过)
#yum -y install ntp (安装ntp对时工具)
#chkconfig ntpd on (让对时服务开机启动)
5、使用 yum 对系统进行更新并且安装必要软件包
#yum update –y
#yum -y install make openssl openssl-devel pcre pcre-devel libpng libpng-devel libjpeg-6b libjpeg-devel-6b freetype freetype-devel gd gd-devel zlib zlib-devel gcc gcc-c++ libXpm libXpm-devel ncurses ncurses-devel libmcrypt libmcrypt-devel libxml2 libxml2-devel imake autoconf automake screen sysstat compat-libstdc++-33 curl curl-devel
6. 重新启动系统
# init 6
三、编译安装L.A.M.P环境
1、下载软件(截止到09年10月的最新版本)
# cd /usr/local/src
#wget http://sysoev.ru/Nginx/Nginx-0.7.63.tar.gz
#wget http://download.scientificlinux.net/Nginx
#wget http://download.scientificlinux.net/PHP-fpm.conf
#wget http://download.scientificlinux.net/Nginx.conf
#wget http://download.scientificlinux.net/fcgi.conf
#wget http://download.scientificlinux.net/PHP-5.2.10.tar.gz
#wget http://download.scientificlinux.net/PHP-5.2.10-fpm-0.5.13.diff.gz
#wget http://download.scientificlinux.net/ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz (32位系统)
#wget http://download.scientificlinux.net/ZendOptimizer-3.3.3-linux-glibc23-x86_64.tar.gz (64位系统)
#wget http://download.scientificlinux.net/MysqL-5.1.39-linux-i686-glibc23.tar.gz (32位系统)
#wget http://download.scientificlinux.net/MysqL-5.1.39-linux-x86_64-glibc23.tar.gz (64位系统)
2、安装MysqL
复制代码
代码如下:
cd /usr/local/src
tar zxvf MysqL-5.1.39-linux-i686-glibc23.tar.gz
mv MysqL-5.1.39-linux-i686-glibc23 /usr/local/
ln -s /usr/local/MysqL-5.1.39-linux-i686-glibc23/ /usr/local/MysqL
groupadd MysqL
useradd -g MysqL MysqL
chown -R MysqL:MysqL /usr/local/MysqL
chown -R MysqL:MysqL /usr/local/MysqL-5.1.39-linux-i686-glibc23/
cd /usr/local/MysqL
./scripts/MysqL_install_db –user=MysqL
cp ./support-files/MysqL.server /etc/rc.d/init.d/MysqLd
chmod 755 /etc/rc.d/init.d/MysqLd
chkconfig –add MysqLd
chkconfig –level 3 MysqLd on
cp ./support-files/my-huge.cnf /etc/my.cnf
mv /usr/local/MysqL/data /var/lib/MysqL
chown -R MysqL:MysqL /var/lib/MysqL
编辑/etc/my.cnf
在 [MysqLd] 段增加
datadir = /var/lib/MysqL
skip-innodb
wait-timeout = 10
max_connections = 512
max_connect_errors = 10000000
在 [MysqLd] 段修改
max_allowed_packet = 16M
thread_cache_size = cpu个数*2
将 log-bin 注释
service MysqLd start
bin/MysqLadmin -u root password ‘password_for_root’
其中引号内的password_for_root是要设置的root密码
3、安装Nginx
复制代码
代码如下:
cd /usr/local/src/
tar zxvf Nginx-0.7.63.tar.gz
cd Nginx-0.7.63
./configure –prefix=/usr/local/Nginx –conf-path=/usr/local/Nginx/conf/Nginx.conf –with-http_realip_module –with-http_addition_module –with-http_gzip_static_module –with-http_random_index_module –with-http_stub_status_module –with-http_sub_module –with-http_dav_module
make
make install
cp /usr/local/src/Nginx /etc/init.d/Nginx
chmod 755 /etc/init.d/Nginx
chkconfig –add Nginx
chkconfig Nginx on
4、安装PHP和Zend
复制代码
代码如下:
cd /usr/local/src
tar zxvf PHP-5.2.10.tar.gz
gzip -cd PHP-5.2.10-fpm-0.5.13.diff.gz | patch -d PHP-5.2.10 -p1
cd PHP-5.2.10
./configure –prefix=/usr/local/PHP5 –with-config-file-path=/usr/local/etc/cgi –enable-mbstring –enable-ftp –with-gd –with-jpeg-dir=/usr –with-png-dir=/usr –enable-magic-quotes –with-MysqL=/usr/local/MysqL –with-pear –enable-sockets –with-ttf –with-freetype-dir=/usr –enable-gd-native-ttf –with-zlib –enable-sysvsem –enable-sysvshm –with-libxml-dir=/usr –enable-force-cgi-redirect –enable-fastcgi –with-xmlrpc –enable-zip –enable-fpm
make
make install
mkdir -p /usr/local/etc/cgi/
cp PHP.ini-dist /usr/local/etc/cgi/PHP.ini
mv -f /usr/local/src/PHP-fpm.conf /usr/local/PHP5/etc/PHP-fpm.conf
groupadd www
useradd -g www www
echo ‘ulimit -SHn 65535’ >> /etc/rc.local
echo ‘/usr/local/PHP5/sbin/PHP-fpm start’ >> /etc/rc.local
cd /usr/local/src
tar zxvf ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz
cd ZendOptimizer-3.3.3-linux-glibc23-i386
./install
(注意第一个要填的路径是Zend安装路径,第二个是PHP.ini所在的路径,即/usr/local/etc/cgi)
(不要选重启apache)
5、启动Nginx和PHP
复制代码
代码如下:
mv -f /usr/local/src/fcgi.conf /usr/local/Nginx/conf/
cp -f /usr/local/src/Nginx.conf /usr/local/Nginx/conf/Nginx.conf
mkdir -p /home/www/wwwroot
ulimit -SHn 65535
/usr/local/PHP5/sbin/PHP-fpm start
service Nginx start
在/home/www/wwwroot放入一个index.PHP,内容为
打开浏览器访问,即可看到PHPinfo页面
6、设置系统防火墙
编辑/usr/local/sbin/fw.sh
复制以下内容进去
复制代码
代码如下:
#!/bin/bash
# Stop iptables service first
service iptables stop
# Load FTP Kernel modules
/sbin/modprobe ip_conntrack_ftp
/sbin/modprobe ip_nat_ftp
# Inital chains default policy
/sbin/iptables -F -t filter
/sbin/iptables -P INPUT DROP
/sbin/iptables -P OUTPUT ACCEPT
# Enable Native Network Transfer
/sbin/iptables -A INPUT -i lo -j ACCEPT
# Accept Established Connections
/sbin/iptables -A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
# ICMP Control
/sbin/iptables -A INPUT -p icmp -m limit –limit 1/s –limit-burst 10 -j ACCEPT
# WWW Service
/sbin/iptables -A INPUT -p tcp –dport 80 -j ACCEPT
# FTP Service
/sbin/iptables -A INPUT -p tcp –dport 21 -j ACCEPT
# SSH Service
/sbin/iptables -A INPUT -p tcp –dport 22 -j ACCEPT
退出编辑,执行以下命令
复制代码
代码如下:
# chmod 755 /usr/local/sbin/fw.sh
# echo ‘/usr/local/sbin/fw.sh’ >> /etc/rc.local
# /usr/local/sbin/fw.sh
CentOS 6 部署 Nginx + PHP5 服务器
CentOS 6 部署 Nginx + PHP5 Web服务器
在 cetnos 6 (64位) 操作系统上部署nginx and php5服务器。这个过程通过 yum 命令进行rpm包安装。
可以参考 PHP 官方文档。
安装 一些必要的 YUM 库
rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpmrpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
安装 Nginx
添加 nginx 的 YUM 库配置文件 /etc/yum.repos.d/nginx.repo,
[nginx]name=nginx repobaseurl=http://nginx.org/packages/centos/$releasever/$basearch/gpgcheck=0enabled=1
root 用户执行:
立即学习“PHP免费学习笔记(深入)”;
# yum install nginx
安装 PHP 及重要插件 php-fpm
root 用户执行:
立即学习“PHP免费学习笔记(深入)”;
# yum install php-fpm
将会安装好 php-fpm 以及 php 本身在内的其他依赖。
配置、启动 php-fpm
配置 /etc/php.ini,设置 cgi.fix_pathinfo=0
启动 php-fpm 并放置后台运行
php-fpm -D
停掉 php-fpm 的方法
root@acx-xiwang:/etc# ps -ef | grep php-fpmroot 31591 1 0 14:09 ? 00:00:00 php-fpm: master process (/etc/php-fpm.conf)apache 31592 31591 0 14:09 ? 00:00:00 php-fpm: pool wwwapache 31593 31591 0 14:09 ? 00:00:00 php-fpm: pool wwwapache 31594 31591 0 14:09 ? 00:00:00 php-fpm: pool wwwapache 31595 31591 0 14:09 ? 00:00:00 php-fpm: pool wwwapache 31596 31591 0 14:09 ? 00:00:00 php-fpm: pool wwwroot 31914 31878 0 14:32 pts/1 00:00:00 grep --color php-fpmroot@acx-xiwang:/etc# kill -s SIGINT 31591
或者通过 service 命令执行
service php-fpm stopservice php-fpm start
配置、启动 Nginx
直接分享我的配置 /etc/nginx/nginx.conf:
user xiwang;events {}http { include /etc/nginx/mime.types; server { root /home/xiwang/opt/www; location / { index index.html index.htm index.php; } error_page 404 /404.html; location ~* \.php$ { fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }}
启动 Nginx 服务器
$ nginx
或者通过 service 命令执行:
service nginx stopservice nginx start
如果运行时修改了配置文件,可以通过 nginx -s reload 来使配置文件生效。
FAQ
如何解决 “NO INPUT FILE SPECIFIED” 的问题,当我们安装 PHP 和 NGINX 的时候
文章: 英文原版
检查 php 文件是否拥有写权限,它的父目录都有执行权限 ?
chmod a+x /home/xiwang/opt #<-- container folder should be granted execute permissionchmod a+x /home/xiwang/opt/www #<-- container folder should be granted execute permissionchmod a+w /home/xiwang/opt/www/*.php #<-- .php file should be granted write permission
centos 6.5下编译安装、配置高性能服务器Nginx
1.Nginx是什么?
Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,由俄罗斯的程序设计师Igor Sysoev所开发,其特点是占有内存少,并发能力强。
2.安装前需要安装pre(作用rewrite)、zlib(作用压缩)、ssl(作用安全证书)安装包。如图:
①安装pre包
yum -y install pcre*
②安装zlib包
yum -y install zlib*
③安装ssl包
yum -y install openssl*
3.下载Nginx,我这里是稳定版本:1.10.1
下载地址:http://nginx.org/en/download.html,登录网站并下载之。
版本看需求,我这里就以稳定版Nginx-1.10.1为例
注意:当然你也可以使用wget命令直接下载相应的版本。
再次为了便于简便,我这里直接使用wget下载命令直接在网络中下载Nginx。如图:
wget http://Nginx.org/download/Nginx-1.10.1.tar.gz
4.解压缩Nginx-1.10.1.tar.gz安装包,如图:
tar –zxvf Nginx-1.10.1.tar.gz
5.删除Nginx-1.10.1.tar.gz安装包,如图:
rm -rf Nginx-1.10.1.tar.gz
6. (此部分可以忽略,因为Nginx-1.10.1版本太高,编译安装的时候会报错,如果需要此功能可使用Nginx-1.6.2版本)实现基于cookie的负载均衡,我这里使用使用Nginx sticky。(声明:在多台后台服务器的环境下,我们为了确保一个客户只和一台服务器通信,我们势必使用长连接。使用什么方式来实现这种连接呢,常见的有使用nginx自带的ip_hash来做,我想这绝对不是一个好的办法,如果前端是CDN,或者说一个局域网的客户同时访问服务器,导致出现服务器分配不均衡,以及不能保证每次访问都粘滞在同一台服务器。如果基于cookie会是一种什么情形,想想看,每台电脑都会有不同的cookie,在保持长连接的同时还保证了服务器的压力均衡,Nginx sticky值得推荐。
如果浏览器不支持cookie,那么sticky不生效,毕竟整个模块是给予cookie实现的.
)。使用rz命令上传已经下载好的Nginx-sticky-module-1.25.zip压缩包到/usr/local目录下。(下载地址:http://download.csdn.net/detail/xushouwei/9599197)
rz
使用unzip命令解压Nginx-sticky-module-1.25.zip压缩包。
unzip Nginx-sticky-module-1.25.zip
7.进入到Nginx-1.10.1目录,编译Nginx。
cd Nginx-1.10.1
./configure --prefix=/usr/local/Nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-pcre
编译参数可参考文档(下载地址:http://download.csdn.net/detail/xushouwei/9599174)
7.安装Nginx
make && make install
8.启动Nginx服务。
/usr/local/Nginx/sbin/Nginx
重启或关闭Nginx进程:
/usr/local/Nginx/sbin/Nginx -s reload
/usr/local/Nginx/sbin/Nginx -s stop
9.关闭防火墙或添加防火墙规则(我这里采用直接关闭防火墙的方式)
关闭防火墙:service iptables stop
或者编辑配置文件:
vi /etc/sysconfig/iptables
添加这样一条开放80端口的规则后保存:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
重启服务即可:
service iptables restart
10.访问测试是否成功。
关于CentOS服务器nginx区分手机与电脑浏览器并进入相应站点和nginx 判断手机还是电脑的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于Cenos服务器中配置nginx、CentOS 5 服务器 Nginx 环境推荐教程、CentOS 6 部署 Nginx + PHP5 服务器、centos 6.5下编译安装、配置高性能服务器Nginx等相关内容,可以在本站寻找。
本文标签: