仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 349|回复: 7
打印 上一主题 下一主题

[其他Linux] 带来一篇linux服务器下LNMP安装与设置办法

[复制链接]
飘飘悠悠 该用户已被删除
跳转到指定楼层
#
发表于 2015-1-16 13:06:13 | 只看该作者 回帖奖励 |正序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
不同版本的Linux命令数量不一样,这里笔者把它们中比较重要的和使用频率最多的命令。
Nginx与apache、lighttp功能综合对照,以下图:



注重:封闭rpm默许安装的apache和mysql
1.筹办php函数的rpm包
yum-yinstallgccgcc-c++autoconflibjpeglibjpeg-devellibpnglibpng-develfreetypefreetype-devellibxml2libxml2-develzlibzlib-develglibcglibc-develglib2glib2-develbzip2bzip2-develncursesncurses-develcurlcurl-devele2fsprogse2fsprogs-develkrb5krb5-devellibidnlibidn-developensslopenssl-developenldapopenldap-develnss_ldapopenldap-clientsopenldap-servers

2.筹办lnmp其他的源代码包
wgethttp://blog.s135.com/soft/linux/nginx_php/nginx/nginx-0.8.46.tar.gz
wgethttp://blog.s135.com/soft/linux/nginx_php/php/php-5.2.14.tar.gz
wgethttp://blog.s135.com/soft/linux/nginx_php/phpfpm/php-5.2.14-fpm-0.5.14.diff.gz
wgethttp://blog.s135.com/soft/linux/nginx_php/mysql/mysql-5.5.3-m3.tar.gz
wgethttp://blog.s135.com/soft/linux/nginx_php/libiconv/libiconv-1.13.1.tar.gz
wgethttp://blog.s135.com/soft/linux/nginx_php/mcrypt/libmcrypt-2.5.8.tar.gz
wgethttp://blog.s135.com/soft/linux/nginx_php/mcrypt/mcrypt-2.6.8.tar.gz
wgethttp://blog.s135.com/soft/linux/nginx_php/memcache/memcache-2.2.5.tgz
wgethttp://blog.s135.com/soft/linux/nginx_php/mhash/mhash-0.9.9.9.tar.gz
wgethttp://blog.s135.com/soft/linux/nginx_php/pcre/pcre-8.10.tar.gz
wgethttp://blog.s135.com/soft/linux/nginx_php/eaccelerator/eaccelerator-0.9.6.1.tar.bz2
wgethttp://blog.s135.com/soft/linux/nginx_php/pdo/PDO_MYSQL-1.0.2.tgz
wgethttp://blog.s135.com/soft/linux/nginx_php/imagick/ImageMagick.tar.gz
wgethttp://blog.s135.com/soft/linux/nginx_php/imagick/imagick-2.3.0.tgz

3.安装php-5.2.14源代码包所必要的函数撑持包
.代码以下:

tarzxvflibiconv-1.13.1.tar.gz
cdlibiconv-1.13.1/
./configure--prefix=/usr/local
make
makeinstall
cd../


(libiconv库为必要做转换的使用供应了一个iconv()的函数,以完成一个字符编码到另外一个字符编码的转换)
.代码以下:

tarzxvflibmcrypt-2.5.8.tar.gz
cdlibmcrypt-2.5.8/
./configure
make
makeinstall
cdlibltdl/
./configure--enable-ltdl-install
make
makeinstall
cd../../


(libmcrypt是加密算法扩大库。撑持DES,3DES,RIJNDAEL,Twofish,IDEA,GOST,CAST-256,ARCFOUR,SERPENT,SAFER+等算法。)
.代码以下:

tarzxvfmhash-0.9.9.9.tar.gz
cdmhash-0.9.9.9/
./configure
make
makeinstall
cd../
(加密算法撑持)
ln-s/usr/local/lib/libmcrypt.la/usr/lib/libmcrypt.la
ln-s/usr/local/lib/libmcrypt.so/usr/lib/libmcrypt.so
ln-s/usr/local/lib/libmcrypt.so.4/usr/lib/libmcrypt.so.4
ln-s/usr/local/lib/libmcrypt.so.4.4.8/usr/lib/libmcrypt.so.4.4.8
ln-s/usr/local/lib/libmhash.a/usr/lib/libmhash.a
ln-s/usr/local/lib/libmhash.la/usr/lib/libmhash.la
ln-s/usr/local/lib/libmhash.so/usr/lib/libmhash.so
ln-s/usr/local/lib/libmhash.so.2/usr/lib/libmhash.so.2
ln-s/usr/local/lib/libmhash.so.2.0.1/usr/lib/libmhash.so.2.0.1
ln-s/usr/local/bin/libmcrypt-config/usr/bin/libmcrypt-config
tarzxvfmcrypt-2.6.8.tar.gz
cdmcrypt-2.6.8/
./configure
make
makeinstall
cd../


4.编译安装MySQL5.5.3-m3
.代码以下:

groupaddmysql
useradd-gmysqlmysql

tarzxvfmysql-5.5.3-m3.tar.gz
cdmysql-5.5.3-m3
./configure--prefix=/usr/local/mysql--without-debug--enable-thread-safe-client--with-pthread--enable-assembler--enable-profiling--with-mysqld-ldflags=-all-static--with-client-ldflags=-all-static--with-extra-charsets=all--with-plugins=all--with-mysqld-user=mysql--without-embedded-server--with-server-suffix=-community--with-unix-socket-path=/tmp/mysql.sock
Make
#编译
Makeinstall
#安装
Cp/usr/local/mysql/share/mysql/my-medium.cnf/etc/my.cnf
#筹办mysql设置文件
Vi/etc/my.cnf
[client]
default-character-set=utf8
#修正客户端和毗连字符集
[mysqld]
character-set-server=utf8
#修正服务器和数据库字符集
collation-server=utf8_general_ci
#修正服务器校验字符集上岸mysql后能够s检察字符集

Setfacl-mu:mysql:rwx-R/usr/local/mysql
Setfacl-md:u:mysql:rwx-R/usr/local/mysql
#设置权限
/usr/local/mysql/bin/mysql_install_db--user=mysql
#安装mysql和test数据库
/usr/local/mysql/bin/mysqld_safe--user=mysql&
#启动mysql服务
/usr/local/mysql/bin/mysqladmin-urootpassword123
#修正mysql登录暗码为123
/usr/local/mysql/bin/mysql-uroot-p123
#用mysql登录


5.编译安装PHP(FastCGI形式。利用fastCGI办理php,加速php剖析速率)
.代码以下:

tarzxvfphp-5.2.14.tar.gz
gzip-cdphp-5.2.14-fpm-0.5.14.diff.gz|patch-dphp-5.2.14-p1
#-p1是数字
#解压并打补钉,让php撑持fpm来便利办理php-cgi历程(利用php-fpm办理fastCGI)
#gzip-c保存源文件-d解压
cdphp-5.2.14/
./configure--prefix=/usr/local/php--with-config-file-path=/usr/local/php/etc--with-mysql=/usr/local/mysql--with-mysqli=/usr/local/mysql/bin/mysql_config--with-iconv-dir=/usr/local--with-freetype-dir--with-jpeg-dir--with-png-dir--with-zlib--with-libxml-dir=/usr--enable-xml--disable-rpath--enable-discard-path--enable-safe-mode--enable-bcmath--enable-shmop--enable-sysvsem--enable-inline-optimization--with-curl--with-curlwrappers--enable-mbregex--enable-fastcgi--enable-fpm--enable-force-cgi-redirect--enable-mbstring--with-mcrypt--with-gd--enable-gd-native-ttf--with-openssl--with-mhash--enable-pcntl--enable-sockets--with-ldap--with-ldap-sasl--with-xmlrpc--enable-zip--enable-soap
makeZEND_EXTRA_LIBS=-liconv
#编译历程设定变量(编译历程必要)
makeinstall
cp/lnmp/php-5.2.14/php.ini-dist/usr/local/php/etc/php.ini
cd../


6.筹办编译安装PHP5扩大模块
.代码以下:

tarzxvfmemcache-2.2.5.tgz
cdmemcache-2.2.5/
/usr/local/php/bin/phpize
./configure--with-php-config=/usr/local/php/bin/php-config
make
makeinstall
cd../
tarjxvfeaccelerator-0.9.6.1.tar.bz2
cdeaccelerator-0.9.6.1/
/usr/local/php/bin/phpize
./configure--enable-eaccelerator=shared--with-php-config=/usr/local/php/bin/php-config
make
makeinstall
cd../
(eAccelerator是一个自在开放源码php减速器,优化和静态内容缓存,进步了php剧本的缓存功能,使得PHP剧本在编译的形态下,对服务器的开支几近完整打消。它另有对剧本起优化感化,以加速其实行效力。使您的PHP程序代码执效力能进步1-10倍)
tarzxvfPDO_MYSQL-1.0.2.tgz
cdPDO_MYSQL-1.0.2/
/usr/local/php/bin/phpize
./configure--with-php-config=/usr/local/php/bin/php-config--with-pdo-mysql=/usr/local/mysql
make
makeinstall
cd../
tarzxvfImageMagick.tar.gz
cdImageMagick-6.5.1-2/
./configure
make
makeinstall
cd../
(ImageMagick是一套功效壮大、不乱并且收费的工具集和开辟包,能够用来读、写和处置凌驾89种基础格局的图片文件,包含盛行的TIFF、JPEG、GIF、PNG、PDF和PhotoCD等格局)
tarzxvfimagick-2.3.0.tgz
cdimagick-2.3.0/
/usr/local/php/bin/phpize
./configure--with-php-config=/usr/local/php/bin/php-config
make
makeinstall
cd../


7.修正php.ini文件,让php模块失效
.代码以下:

vi/usr/local/php/etc/php.ini
extension_dir="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"

手工增加
extension="memcache.so"
extension="pdo_mysql.so"
extension="imagick.so"
再查找output_buffering=Off
修正为output_buffering=On
再查找;cgi.fix_pathinfo=0
修正为cgi.fix_pathinfo=0,避免Nginx文件范例毛病剖析毛病


8.在php.ini中设置eAccelerator减速PHP
.代码以下:

mkdir-p/usr/local/eaccelerator_cache
#筹办eaccelerator缓存目次

vi/usr/local/php/etc/php.ini
[eaccelerator]
zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="64"
eaccelerator.cache_dir="/usr/local/eaccelerator_cache"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="3600"
eaccelerator.shm_prune_period="3600"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"


9.筹办php-cgi和nginx历程实行者用户
useraddnginx

10.创立php-fpm设置文件-php-fpm.conf
vi/usr/local/php/etc/php-fpm.conf
<valuename="display_errors">0</value>
#0改成1,页面上会输入毛病日记.作废正文
unixuserofprocesses
<valuename="user">nginx</value>
Unixgroupofprocesses
<valuename="group">nginx</value>作废正文
<valuename="max_children">128</value>
#最年夜子历程数128,假如内存小于2G,则64个最好
<valuename="rlimit_files">65535</value>
#Setopenfiledescrlimit,同时翻开的文件数,linux体系同意同时翻开的文件数为1024,修正linux体系中同意同时翻开的文件,ulimit-SHn65535,并且这个参数重启后还能失效,加到/etc/profile全局设置文件的最初,开机就会失效,ulimit-a检察openfiles65535
ulimit用户把持shell启动历程所占用的资本
-H设定硬性资本限定,也就是办理员设定的限定
-S设定软性资本限定,弹性限定
-n设定可同时翻开的最年夜文件个数
-f设订单个文件最年夜巨细
-a检察今朝的限定
<valuename="max_requests">1024</value>
#最年夜哀求数,Howmuchrequestseachprocessshouldexecutebeforerespawn.一个子历程可以回应1042个哀求

11.启动php-cgi(fastcgi)历程,监听127.0.0.1的9000端口,历程数为128(假如服务器内存小于3GB,能够只开启64个历程),用户为nginx:
.代码以下:

/usr/local/php/sbin/php-fpmstart
#启动php-cgi
/usr/local/php/sbin/php-fpmreload
#从头加载设置文件
/usr/local/php/sbin/php-fpmstop
#封闭php-fpm,此时nginx一定连不上php


12.安装Nginx所需的pcre库
.代码以下:

tarzxvfpcre-8.10.tar.gz
cdpcre-8.10/
./configure
make&&makeinstall
cd../


13.安装Nginx
.代码以下:

tarzxvfnginx-0.8.46.tar.gz
cdnginx-0.8.46/
./configure--user=nginx--group=nginx--prefix=/usr/local/nginx--with-http_stub_status_module--with-http_ssl_module
make&&makeinstall
cd../


14.修正Nginx设置文件
.代码以下:

vi/usr/local/nginx/conf/nginx.conf
usernginxnginx;
worker_processes1;
#相称于cpu个数
error_loglogs/nginx_error.log;
#毛病日记
pid/usr/local/nginx/nginx.pid;
#主历程PID保留文件
#Specifiesthevalueformaximumfiledescriptorsthatcanbeopenedbythisprocess.
worker_rlimit_nofile65535;
#文件形貌符数目
events
{
useepoll;
#收集I/O模子,倡议linux利用epoll,FreeBSD利用kqueue
worker_connections65535;
#最年夜同意毗连数
}
http
{
includemime.types;
default_typeapplication/octet-stream;
log_formatmain$remote_addr-$remote_user[$time_local]"$request"
$status$body_bytes_sent"$http_referer"
"$http_user_agent""$http_x_forwarded_for";
#日记格局
access_loglogs/access.logmain;
#挪用格局的日记

sendfileon;
tcp_nopushon;
#tcp提早
keepalive_timeout65;
#坚持毗连工夫
fastcgi_connect_timeout300;
fastcgi_send_timeout300;
fastcgi_read_timeout300;
fastcgi_buffer_size64k;
fastcgi_buffers464k;
fastcgi_busy_buffers_size128k;
fastcgi_temp_file_write_size128k;
#fastcgi设置
gzipon;
gzip_min_length1k;
gzip_buffers416k;
gzip_http_version1.0;
gzip_comp_level2;
gzip_typestext/plainapplication/x-javascripttext/CSSapplication/xml;
gzip_varyon;
#收集紧缩设置
#limit_zonecrawler$binary_remote_addr10m;
server
{
listen80;
#监听端口
server_name192.168.150.253;
#主机名,或IP。假如是主机名,要可以DNS剖析

location/{
roothtml;
#网站主目次。/usr/local/nginx/html/
indexindex.htmlindex.htmindex.php;
#默许网页按次
}

#limit_conncrawler20;

location~.*.(php|php5)?$
#~:婚配前面正则表达式:.*恣意字符.点php或php5开头。碰着网页文
件名是.php或.php5开头
{
roothtml;
#fastcgi_passunix:/tmp/php-cgi.sock;
fastcgi_pass127.0.0.1:9000;
#毗连fastcgi,用来剖析php语句
fastcgi_indexindex.php;
#首页为index.php
#fastcgi_paramSCRIPT_FILENAME/scripts$fastcgi_script_name
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
#启动fast-cgi,能够在每一个服务中启动,也能够放进/usr/local/nginx/conf/fastcgi_params,每一个server都能够享用
includefastcgi_params;
#包含fastcgi_params中参数
}

location~.*.(gif|jpg|jpeg|png|bmp|swf)$
{
expires30d;
#图片格局缓存30天
}
location~.*.(js|css)?$
{
expires1h;
#js/css缓存2小时
}
log_formataccess$remote_addr-$remote_user[$time_local]"$request"
$status$body_bytes_sent"$http_referer"
"$http_user_agent"$http_x_forwarded_for;
access_log/data1/logs/access.logaccess;
}
}


15.在/usr/local/nginx/conf/目次中创立fastcgi_params文件
.代码以下:

Vi/usr/local/nginx/conf/fastcgi_params(与设置文件中,只写一个就好)
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;



#倡议把fastcgi_param写到nginx.conf中而不是把它写到fastcgi_params设置文件中,不然设置不敷天真,好比前面默许php设置和aliasphp设置中,他们的php页面的体系地点是分歧的,好比:
默许php文件->/usr/local/nginx/html/index.php
Aliasphp文件->/mnt/bbs/index.php
这个时分你会发明fastcgi_params中的SCRIPT_FILENAME的值是不异的,如许会招致aliasphp的页面出不来,而设置在nginx.conf中各自设置各自的php体系地点,如许对照天真.

#假如你以为每一个毗连php的设置中都要加这一句话有点冗余,那就把它到场到fastcgi_params文件中,如许只必要加一次,其他一切的nginx.conf中的有干系接fastcgi的一块就不必加fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name这一句话了.
16.设置开机启动nginx,php-fpm,ulimit
1)nginx
Vi/etc/rc.local
/usr/local/nginx/sbin/nginx
2)php-fpm
Vi/etc/rc.local
/usr/local/php/sbin/php-fpmstart
3)ulimit
Vi/etc/profile
ulimit-SHn65535
4)mysql
Vi/etc/rc.local
/usr/local/mysql/bin/mysqld_safe--user=mysql&

17.反省nginx设置文件语句毛病
/usr/local/nginx/sbin/nginx-t

18.光滑重启nginx历程
1)Pkill-HUPnginx
2)kill-HUP`pgrep-urootnginx`
Pgrep-urootnginx掏出nginx主历程PID
3)/usr/local/nginx/sbin/nginx-sreload

19.编写天天准时切割Nginx日记的剧本
1、创立剧本/usr/local/nginx/sbin/cut_nginx_log.sh
vi/usr/local/nginx/sbin/cut_nginx_log.sh

#!/bin/bash
#Thisscriptrunat00:00
#TheNginxlogspath
logs_path="/usr/local/nginx/logs/"
mkdir-p${logs_path}$(date-d"yesterday"+"%Y")/$(date-d"yesterday"+"%m")/
mv${logs_path}access.log${logs_path}$(date-d"yesterday"+"%Y")/$(date-d"yesterday"+"%m")/access_$(date-d"yesterday"+"%Y%m%d").log
kill-USR1`cat/usr/local/nginx/nginx.pid`
2、设置crontab,天天清晨00:00切割nginx会见日记
crontab-e
0000***/bin/bash/usr/local/nginx/sbin/cut_nginx_log.sh
20.设置nginx假造主机

Sina和sohu域名事前剖析
.代码以下:

Vi/usr/local/nginx/conf/nginx.conf
==èwww.ckuyun.com公司网站
server{
listen80;
server_namewww.ckuyun.com;
access_loglogs/sina.access.logmain;
location/{
root/web/sina;
indexindex.htmlindex.htm;
}
error_page500502503504/50x.html;
location=/50x.html{
roothtml;
}
location~.php${
root/web/sina;
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
includefastcgi_params;
}
}
==èwww.sohu.com公司网站

server{
listen80;
server_namewww.sohu.com;
access_loglogs/sohu.access.logmain;
location/{
root/web/sohu;
indexindex.htmlindex.htm;
}
error_page500502503504/50x.html;
location=/50x.html{
roothtml;
}
location~.php${
root/web/sohu;
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
#fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
includefastcgi_params;
}


最初在客户端测试假造主机www.baidu.com和www.ckuyun.com两家公司网站

21.列表页显现
location/{
autoindexon;#翻开列表页
roothtml;
indexindex.htmlindex.phpindex.htm;
}

22.假造目次设置
location/bbs{
alias/mnt/bbs/;
}
#如许设置html静态文件是能够出来的,可是php静态页面出不来,并且会扫瞄器的页面上会显现"Noinputfilespecified."的报错,实际上是php体系文件地点(SCRIPT_FILENAME)找不到,也就是说fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;中的$document_root$fastcgi_script_name不是真实的/mnt/bbs/index.php的地点,这可怎样办理:
location/bbs{
alias/mnt/bbs/;
indexbbs.phpindex.htmlindex.php;
}
location~^/bbs/{
root/mnt/;
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
includefastcgi_params;
log_formatbbs$document_root$fastcgi_script_name;
access_loglogs/bbs.access.logbbs;
}
#前面两行是关于日记的,就是为了更好的察看由nginx提交给fastcgi的php的体系地点SCRIPT_FILENAME,在这里我用$request_filename来给SCRIPT_FILENAME赋值,在日记中的了局为/mnt/bbs/index.php,在这里我发明一个成绩就是$request_filename中的root设置为/mnt,不然$request_filename的值为:/mnt/bbs/bbs/index.php.

由以上能够失掉一个结论,就是默许php设置也能够如许设置关于SCRIPT_FILENAME:
location~.php${
roothtml;
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
includefastcgi_params;
log_formatphp$document_root$fastcgi_script_name;
access_loglogs/php.access.logphp;
}
#此时从日记中能够看到,$request_filename的值为/usr/local/nginx/html/index.php,而之前默许的/scripts$fastcgi_script_name明显是错的php体系地点,日记中显现为/scripts/index.php
23.nginx形态监控
location/nginxstatus{
stub_statuson;
access_logoff;
}
#客户端会见网址:http://www.baidu.com/nginxstatus

24.rewrite正则过滤
location~.php${
proxy_passhttp://127.0.0.1;
}
Rewrite指令最初一项参数为flag标志,撑持的flag标志以下:
Last标示完成rewrite划定规矩
Break不再婚配前面的划定规矩
Redirect302一时重定向
Permanent301永世重定向
Last和break用来完成uri重写,扫瞄器地点栏的url地点稳定,但在服务器会见的路径产生了变更,redirect和permanent用来完成url跳转,扫瞄器地点栏会显现跳转后的url地点,利用alias指令时必需利用last标志,利用proxy_pass指令时要利用break标志,last标志在本条rewrite划定规矩实行终了后,会对其地点的server{}标签从头倡议哀求,而break标志则在本条划定规矩婚配完成后,停止婚配,不再婚配前面的划定规矩.

在婚配的过程当中,nginx将起首婚配字符串,然后再婚配正则表达式,婚配到第一个正则表达式后,会中断搜刮,假如婚配到正则表达式,则利用正则表达式的搜刮了局,假如没有婚配到正则表达式,则利用字符串的搜刮了局.
可使用前缀"^~"来克制婚配到字符串后,再往反省正则表达式,婚配到url后,将中断查询.
利用前缀"="能够举行准确的url婚配,假如找到婚配的uri,则中断查询,比方"location=/",只能婚配到"/",而"/test.html"则不克不及被婚配.
正则表达式的婚配,依照它们在设置文件中的按次举行,写在后面的优先.
Location=/{
#仅仅婚配/
[configurationA]
}
Location/{
#婚配任何故/开首的查询,可是正则表达式及较长的字符串(/bbs/)将被优先婚配.
[configurationB]
}
Location^~/images/{
#婚配任何故/images/开首的字符串,而且中断搜刮,以是正则表达式将不会被反省.
[configurationC]
}
Location~*.(gif|jpg|jpeg)${
#婚配以.gif、.jpg、.jpeg开头的任何哀求,可是,/images/内的哀求将利用configurationc的设置
[configuratoinD]
}
哀求处置婚配了局示例:
/->configurationA;
/documents/document.html->configurationB;
/images/1.gif->configurationc;
/documents/1.jpg->configurationD;

例1:域名跳转
输出www.ckuyun.com,跳转到www.sohu.com
server{
listen80;
server_namewww.ckuyun.com;
access_loglogs/sina.access.logmain;
location/{
root/web/sina;
indexindex.htmlindex.htm;
if(-e$request_filename){
#-e是不是存在
rewrite^/http://www.sohu.com/permanent;
#^/域名以/开首。//www.ckuyun.com,也能够写为.*恣意都跳转
}
}
error_page500502503504/50x.html;
location=/50x.html{
roothtml;
}
}
server{
listen80;
server_namewww.sohu.com;
access_loglogs/sohu.access.logmain;
location/{
root/web/sohu;
indexindex.htmlindex.htm;
}
error_page500502503504/50x.html;
location=/50x.html{
roothtml;
}
}

例2:静态index.html跳转到静态index.php文件
cd/web/sina/
viindex.php
<?
print_r($_GET);
?>
Vinginx.conf
server{
listen80;
server_namewww.ckuyun.com;
access_loglogs/sina.access.logmain;
location/{
root/web/sina;
indexindex.htmlindex.htm;
rewrite^/index(d+).html/index.php?id=$1last;
#^/以/开首。d+多个数字。()第一个变量。/index.php?id=$1把第一个变量付与id变量,传进index.php文件
}
error_page500502503504/50x.html;
location=/50x.html{
roothtml;
}
location~.php${
root/web/sina;
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
includefastcgi_params;
}
}

在客户端输出:http://www.ckuyun.com/index2.html
会跳转到index.php,把2当变量传进index.php程序

25.代办署理负载平衡手艺(反向代办署理)
upstreammyweb1{
#界说地点池

192.168.190.190


反向代办署理

upstreammyweb1{

server192.168.190.190:80;
server192.168.190.191:80;

}



server{

listen80;

server_namewww.sohu.com;

location/{

proxy_passhttp://myweb1;

proxy_set_headerHost$host;

proxy_set_headerX-Forwarded-For$remote_addr;

}

}


server192.168.244.10:80;

server192.168.244.11:80;
}
server{
listen80;
server_namewww.sohu.com;



192.168.190.191


#利用www.sohu.com会见

location/{
proxy_passhttp://myweb1;
#利用地点池
proxy_set_headerHost$host;
#使用HOST变量向后端服务器传送必要剖析的客户端会见的域名(传送域名)
proxy_set_headerX-Forwarded-For$remote_addr;
#$remote_addr把客户端实在IP付与X-Forwarded-For。后端服务器才干猎取实在的客户端IP。以便纪录日记,要克日志中纪录的会见信息都是负载服务器,而不是客户端(传送IP)
}
}


26.模块设置
Error_log
#毛病日记
Include
#包括子设置文件,0.6版本今后子设置文件放在nginx.conf地点的路径下
Pid
#主历程id号
User
#nginxnginx标明nginx历程的实行者和组
Worker_processes
#与cpu个数不异,4核cpu为4
Worker_rlimit_nofile65535
#翻开的文件形貌符,不外提早得设置ulimit-SHn65535,即linux同意的翻开文件个数
Worker_connectiones65535
#客户端最年夜毗连数65535
Alias
#假造目次
Error_page
#404,500毛病跳转页面
Index
#indexindex.html,设置默许首页
Keepalive_timeout
#即tcp延续毗连超不时间
Limit_rate
#limit_rate100k,即限速为100KB/s
Limit_rate_after
#limit_rate_after1m,即下载文件凌驾1m,则进进limit_rate限速阶段
Listen
#listen192.168.100.1:80,即设置ip和端口
Location
#该指令同意对分歧的uri举行分歧的设置,能够是字符串、正则表达式
Resolver
#resolver8.8.8.8,为nginx设置dns域名指向
Root
#设置网站根目次
Send_timeout
#超不时间是指举行了两次tcp握手,还没有转为established形态的工夫,假如凌驾这个工夫,客户没有呼应,nginx则封闭毗连,能够用来避免ddos打击
Sendfile
#启用或禁用sendfile()函数,感化于拷贝两个文件形貌符之间的操纵函数,这个拷贝是在内核中操纵的,比read和write拷贝高效很多
Server
#一般web设置或假造主机的设置的地区
Server_name
#依据客户端哀求header头信息中的host域名,来婚配该哀求应当由哪一个假造主机设置或服务器的ip
Tcp_nodelay
#封装tcp/ip数据包的守候工夫,也叫纳格算法,在keepalive开启才有效
Tcp_nopush
#请求sendfile开启的时分才起感化,设置该选择的缘故原由是nginx在linux上,试图在一个包中发送它的httpd应对头
Allow
#allow192.168.100.254,只同意192.168.100.254会见
Deny
#denyall,回绝其他任何人会见
Autoindex
#autoindexon,即开启列表页功效
Charset
#charsetutf8;source_charsetgbk,把服务器上的gbk网页编码转换成utf8输入给客户端
Fastcgi_pass
#fastcgi_pass127.0.0.1:9000;
#fastcgi_indexindex.php;
#fastcgi_paramSCRIPT_FILENAME/scripts$fastcgi_script_name;
#includefastcgi_params;
#fastcgi_pass后跟的是php-cgi历程的ip和端口
Access_log
#准确日记
Proxy_pass
#proxy_passhttp://myweb1,即后跟的是nginx代办署理负载池upstream中的服务器
Proxy_set_header
#proxy_set_headerHost$host,设置把$host带给后真个nginx服务器
Proxy_temp_path
#用户指定一个当地目次缓冲较年夜的代办署理哀求,相似于client_body_temp_path
Stub_status
#stub_statuson,即开户形态监控
Image_filter
#它指定合用于图片的转换范例




















常常有些朋友在Linux论坛问一些问题,不过,其中大多数的问题都是很基的。
海妖 该用户已被删除
7#
发表于 2015-3-21 19:50:20 | 只看该作者
工具书对于学习者而言是相当重要的。一本错误观念的工具书却会让新手整个误入歧途。目前国内关于Linux的书籍有很多不过精品的不多。
山那边是海 该用户已被删除
6#
发表于 2015-3-15 03:46:01 | 只看该作者
我想即使Linux高手也很难快速准确精练的回答你。
透明 该用户已被删除
5#
发表于 2015-2-24 03:47:08 | 只看该作者
尽量不要提问纯属是扯蛋.学习Linux特别是自己一个人初学入手的时候没人教很困难.当然如果可以的话平时多去买些Linux书...对学习Linux很有帮助.
精灵巫婆 该用户已被删除
地板
发表于 2015-2-8 02:31:13 | 只看该作者
老实说,第一个程序是在C中编译好的,调试好了才在Linux下运行,感觉用vi比较麻烦,因为有错了不能调试,只是提示错误。
柔情似水 该用户已被删除
板凳
发表于 2015-2-2 15:18:49 | 只看该作者
眼看这个学期的Linux课程已经告一段落了,我觉得有必要写一遍心得体会来总结一下这学期对着门课程的学习。
变相怪杰 该用户已被删除
沙发
发表于 2015-1-24 22:02:57 | 只看该作者
linux鸟哥的私房菜,第三版,基础篇,网上有pdf下的,看它的目录和每章的介绍就行了,这个绝对原创!
简单生活 该用户已被删除
楼主
发表于 2015-1-18 10:10:59 | 只看该作者
现在的linux操作系统如redhat,难点,红旗等,都是用这么一个内核,加上其它的用程序(包括X)构成的。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-9-29 14:35

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表