文档库 最新最全的文档下载
当前位置:文档库 › Nginx搭建(完整版)

Nginx搭建(完整版)

Nginx搭建(完整版)
Nginx搭建(完整版)

目录

1搭建nginx需要的安装包-----------------------------------------------------------------------2 2前期准备--------------------------------------------------------------------------------------------2

2.1 检测-----------------------------------------------------------------------------------------2

2.2安装libiconv-1.13--------------------------------------------------------------------------2

2.3安装libmcrypt-2.5.8.----------------------------------------------------------------------2

2.4安装mhash-0.9.9.9-------------------------------------------------------------------------2

2.5安装mcrypt-2.6.8--------------------------------------------------------------------------3

3安装mysql------------------------------------------------------------------------------------------3 3.1创建用户和组--------------------------------------------------------------------------------3 3.2安装编译--------------------------------------------------------------------------------------3 3.3创建MySQL数据库存放目录------------------------------------------------------------3 3.4创建https://www.wendangku.net/doc/f1231196.html,f配置文件-----------------------------------------------------------------------3 3.5创建管理MySQL数据库的shell脚本---------------------------------------------------5 3.6创建账户,赋予关闭的权限----------------------------------------------------------------6 4安装编译php----------------------------------------------------------------------------------------6 4.1 编译php---------------------------------------------------------------------------------------6 4.2编译安装PHP扩展模块--------------------------------------------------------------------7

4.2.1编译memcache--------------------------------------------------------------------------7

4.2.2编译eaccelerator-0.9.

5.3--------------------------------------------------------------7

4.2.3编译PDO_MYSQL-1.0.2-------------------------------------------------------------7

4.2.4编译ImageMagick----------------------------------------------------------------------7

4.2.5编译imagick-2.2.2-----------------------------------------------------------------------7

4.3 修改php配置文件------------------------------------------------------------------------7

4.4配置eAccelerator加速PHP--------------------------------------------------------------8

4.5创建www用户和组------------------------------------------------------------------------8

4.6创建虚拟机目录-----------------------------------------------------------------------------8

4.7创建php-fpm配置文件--------------------------------------------------------------------8

4.8启动php-cgi进程---------------------------------------------------------------------------12 5安装编译nginx-----------------------------------------------------------------------------------12

5.1安装Nginx所需的pcre库---------------------------------------------------------------12

5.2安装Nginx----------------------------------------------------------------------------------12

5.3建Nginx配置文件-------------------------------------------------------------------------12

5.4启动Nginx-----------------------------------------------------------------------------------12

5.5配置开机自动启动Nginx + PHP--------------------------------------------------------13

5.6优化Linux内核参数-----------------------------------------------------------------------13

5.7在不停止Nginx服务的情况下平滑变更Nginx配置--------------------------------13

5.7.1检查配置文件---------------------------------------------------------------------------13

5.7.2 nginx进程--------------------------------------------------------------------------------14

5.8编写每天定时切割Nginx日志的脚本---------------------------------------------------14

5.8.1创建脚本---------------------------------------------------------------------------------14

5.8.2添加自动任务----------------------------------------------------------------------------14

6 安装编译memcached-------------------------------------------------------------------------------15

6.1 安装编译libevent-----------------------------------------------------------------------------15

6.2 安装编译memcached------------------------------------------------------------------------15

6.3 启动memcached守护进程-----------------------------------------------------------------15

6.4 php使用测试--------------------------------------------------------------------------------15

6.5 停止memcached服务-----------------------------------------------------------------------15

1、搭建nginx需要的安装包

放在219.234.83.29服务器上

cd /home/chenjl/software/nginx0.8_basepacage

2、前期准备

2.1需要安装一些常用的包,在安装服务器时选择安装开发工具,会安装一些常用的包,

如果安装了yum,可以用检测一下(【适用CentOS操作系统】)

yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

2.2安装libiconv-1.1

3.tar.gz

tar zxvf libiconv-1.13.tar.gz

cd libiconv-1.13/

./configure --prefix=/usr/local

make

make install

2.3安装libmcrypt-2.5.8.tar.gz

tar zxvf libmcrypt-2.5.8.tar.gz

cd libmcrypt-2.5.8/

./configure

make

make install

/sbin/ldconfig

cd libltdl/

./configure --enable-ltdl-install

make

make install

2.4安装mhash-0.9.9.9.tar.gz

tar zxvf mhash-0.9.9.9.tar.gz

cd mhash-0.9.9.9/

./configure

make

make install

ln -s /usr/local/lib/https://www.wendangku.net/doc/f1231196.html, /usr/lib/https://www.wendangku.net/doc/f1231196.html,

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/https://www.wendangku.net/doc/f1231196.html, /usr/lib/https://www.wendangku.net/doc/f1231196.html,

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

2.5安装mcrypt-2.6.8.tar.gz

tar zxvf mcrypt-2.6.8.tar.gz

cd mcrypt-2.6.8/

/sbin/ldconfig

./configure

make

make install

3、安装mysql

3.1 创建用户和组

/usr/sbin/groupadd mysql

/usr/sbin/useradd -g mysql mysql

3.2 安装编译

tar zxvf mysql-5.1.38.tar.gz

cd mysql-5.1.38/

./configure --prefix=/usr/local/mysql/ --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=innobase

make && make install

chmod +w /usr/local/mysql

chown -R mysql:mysql /usr/local/mysql

mkdir -p /usr/local/mysqldata/

3.3创建MySQL数据库存放目录

chown -R mysql:mysql /usr/local/mysql/data/

/usr/local/mysql/bin/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql /data --user=mysql

3.4创建https://www.wendangku.net/doc/f1231196.html,f配置文件

输入以下内容:

###############################

[client]

default-character-set = utf8

port = 3306

socket = /tmp/mysql.sock

[mysql]

prompt="(\u:https://www.wendangku.net/doc/f1231196.html,:)[\d]> "

no-auto-rehash

[mysqld]

#default-character-set = utf8

user = mysql

port = 3306

socket = /tmp/mysql.sock

basedir = /usr/local/mysql

datadir = /usr/local/mysql/data

open_files_limit = 10240

back_log = 600

max_connections = 3000

max_connect_errors = 6000

table_cache = 614

external-locking = FALSE

max_allowed_packet = 32M

sort_buffer_size = 2M

join_buffer_size = 2M

thread_cache_size = 300

thread_concurrency = 8

query_cache_size = 32M

query_cache_limit = 2M

query_cache_min_res_unit = 2k

default-storage-engine = MyISAM

default_table_type = MyISAM

thread_stack = 192K

transaction_isolation = READ-COMMITTED tmp_table_size = 246M

max_heap_table_size = 246M

long_query_time = 1

log_long_format

log-bin = /data0/mysql/3306/binlog

binlog_cache_size = 4M

binlog_format = MIXED

max_binlog_cache_size = 8M

max_binlog_size = 512M

expire_logs_days = 7

key_buffer_size = 256M

read_buffer_size = 1M

read_rnd_buffer_size = 16M

bulk_insert_buffer_size = 64M

myisam_sort_buffer_size = 128M

myisam_max_sort_file_size = 10G

myisam_max_extra_sort_file_size = 10G myisam_repair_threads = 1

myisam_recover

skip-name-resolve

master-connect-retry = 10

slave-skip-errors = 1032,1062,126,1114,1146,1048,1396

server-id = 1

innodb_additional_mem_pool_size = 16M

innodb_buffer_pool_size = 2048M

innodb_data_file_path = ibdata1:1024M:autoextend

innodb_file_io_threads = 4

innodb_thread_concurrency = 8

innodb_flush_log_at_trx_commit = 2

innodb_log_buffer_size = 16M

innodb_log_file_size = 128M

innodb_log_files_in_group = 3

innodb_max_dirty_pages_pct = 90

innodb_lock_wait_timeout = 120

innodb_file_per_table = 0

[mysqldump]

quick

max_allowed_packet = 32M

以上数据,根据需要做修改;

3.5创建管理MySQL数据库的shell脚本

#!/bin/sh

mysql_port=3306

mysql_username="chenjl"

mysql_password="cjl1981"

function_start_mysql()

{

printf "Starting MySQL...\n"

/bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/https://www.wendangku.net/doc/f1231196.html,f 2>&1 > /dev/null &

}

function_stop_mysql()

{

printf "Stoping MySQL...\n"

/usr/local/mysql/bin/mysqladmin -u ${mysql_username} -p${mysql_password} -S /tmp/mysql.sock shutdown

}

function_restart_mysql()

{

printf "Restarting MySQL...\n"

function_stop_mysql

sleep 5

function_start_mysql

}

function_kill_mysql()

{

kill -9 $(ps -ef | grep 'bin/mysqld_safe' | grep ${mysql_port} | awk '{printf $2}')

kill -9 $(ps -ef | grep 'libexec/mysqld' | grep ${mysql_port} | awk '{printf $2}')

}

if [ "$1" = "start" ]; then

function_start_mysql

elif [ "$1" = "stop" ]; then

function_stop_mysql

elif [ "$1" = "restart" ]; then

function_restart_mysql

elif [ "$1" = "kill" ]; then

function_kill_mysql

else

printf "Usage: /data0/mysql/${mysql_port}/mysql {start|stop|restart|kill}\n"

fi

chmod 755 /usr/local/mysql/bin/mysql.sh

3.6 创建账户,赋予关闭的权限

/usr/local/mysql/bin/mysql -u root -p -S /tmp/mysql.sock

GRANT ALL PRIVILEGES ON *.* TO 'chenjl'@'localhost' IDENTIFIED BY 'cjl1981';

GRANT ALL PRIVILEGES ON *.* TO 'chenjl'@'127.0.0.1' IDENTIFIED BY 'cjl1981;

4、安装编译php

4.1 编译php

tar zxvf php-5.2.10.tar.gz

gzip -cd php-5.2.10-fpm-0.5.11.diff.gz | patch -d php-5.2.10 -p1

cd php-5.2.10/

./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 --without-pear

make ZEND_EXTRA_LIBS='-liconv'

make install

cp php.ini-dist /usr/local/php/etc/php.ini

curl https://www.wendangku.net/doc/f1231196.html,/go-pear | /usr/local/php/bin/php

4.2编译安装PHP扩展模块

4.2.1 编译memcache

tar zxvf memcache-2.2.5.tgz

cd memcache-2.2.5/

/usr/local/php/bin/phpize

./configure --with-php-config=/usr/local/php/bin/php-config

make

make install

启动方式:

/usr/local/bin/memcached -d -m 64 -u root -l 127.0.0.1 -p 11211 -c 1024 -P /tmp/memcached.pid

4.2.2 编译eaccelerator-0.9.

5.3

tar jxvf eaccelerator-0.9.5.3.tar.bz2

cd eaccelerator-0.9.5.3/

/usr/local/php/bin/phpize

./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config

make

make install

4.2.3编译PDO_MYSQL-1.0.2

tar zxvf PDO_MYSQL-1.0.2.tgz

cd PDO_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

make install

4.2.4编译ImageMagick

tar zxvf ImageMagick.tar.gz

cd ImageMagick-6.5.1-2/

./configure tar zxvf imagick-2.2.2.tgz

make

make instal

4.2.5 编译imagick-2.2.2

tar zxvf imagick-2.2.2.tgz

cd imagick-2.2.2/

/usr/local/php/bin/phpize

./configure --with-php-config=/usr/local/php/bin/php-config

make

make install

4.3 修改php配置文件

手工修改:查找/usr/local/php/etc/php.ini中的extension_dir = "./"

修改为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

4.4配置eAccelerator加速PHP

mkdir -p /usr/local/eaccelerator_cache

vi /usr/local/php/etc/php.ini

按shift+g键跳到配置文件的最末尾,加上以下配置信息:

[eaccelerator]

zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eacceler ator.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"

https://www.wendangku.net/doc/f1231196.html,press="1"

https://www.wendangku.net/doc/f1231196.html,press_level="9"

4.5创建www用户和组

usr/sbin/groupadd www

/usr/sbin/useradd -g www www

4.6创建虚拟机目录

Mkdir /usr/local/www

Chown –R www:www /usr/local/www

4.7创建php-fpm配置文件

All relative paths in this config are relative to php's install prefix

Pid file

/usr/local/php/logs/php-fpm.pid

Error log file

/usr/local/php/logs/php-fpm.log

Log level

notice

When this amount of php processes exited with SIGSEGV or SIGBUS ...

10

... in a less than this interval of time, a graceful restart will be initiated.

Useful to work around accidental curruptions in accelerator's shared memory. 1m

Time limit on waiting child's reaction on signals from master

5s

Set to 'no' to debug fpm

yes

Name of pool. Used in logs and stats.

default

Address to accept fastcgi requests on.

Valid syntax is 'ip.ad.re.ss:port' or just 'port' or '/path/to/unix/socket'

127.0.0.1:9000

Set listen(2) backlog

-1

Set permissions for unix socket, if one used.

In Linux read/write permissions must be set in order to allow connections from web server.

Many BSD-derrived systems allow connections regardless of permissions.

0666

Additional php.ini defines, specific to this pool of workers.

/usr/sbin/sendmail -t -i

1

Unix user of processes

www

Unix group of processes

www

Process manager settings

Sets style of controling worker process count.

Valid values are 'static' and 'apache-like'

static

Sets the limit on the number of simultaneous requests that will be served.

Equivalent to Apache MaxClients directive.

Equivalent to PHP_FCGI_CHILDREN environment in original php.fcgi

Used with any pm_style.

128

Settings group for 'apache-like' pm style

Sets the number of server processes created on startup.

Used only when 'apache-like' pm_style is selected

20

Sets the desired minimum number of idle server processes.

Used only when 'apache-like' pm_style is selected

5

Sets the desired maximum number of idle server processes.

Used only when 'apache-like' pm_style is selected

35

The timeout (in seconds) for serving a single request after which the worker process will be terminated

Should be used when 'max_execution_time' ini option does not stop script execution for some reason

'0s' means 'off'

0s

The timeout (in seconds) for serving of single request after which a php backtrace will be dumped to slow.log file

'0s' means 'off'

0s

The log file for slow requests

logs/slow.log

Set open file desc rlimit

65535

Set max core size rlimit

0

Chroot to this directory at the start, absolute path

Chdir to this directory at the start, absolute path

Redirect workers' stdout and stderr into main error log.

If not set, they will be redirected to /dev/null, according to FastCGI specs

yes

How much requests each process should execute before respawn.

Useful to work around memory leaks in 3rd party libraries.

For endless request processing please specify 0

Equivalent to PHP_FCGI_MAX_REQUESTS

102400

Comma separated list of ipv4 addresses of FastCGI clients that allowed to connect.

Equivalent to FCGI_WEB_SERVER_ADDRS environment in original php.fcgi (5.2.2+) Makes sense only with AF_INET listening socket.

127.0.0.1

Pass environment variables like LD_LIBRARY_PATH

All $V ARIABLEs are taken from current environment

$HOSTNAME

/usr/local/bin:/usr/bin:/bin

/tmp

/tmp

/tmp

$OSTYPE

$MACHTYPE

2

注:请将以下的0改为1,以便显示PHP错误信息,否则,Nginx 会报状态为500的空白错误页)

4.8启动php-cgi进程,监听127.0.0.1的9000端口,进程数为200(如果服务器内存小于3GB,可以只开启64个进程),用户为www:

ulimit -SHn 65535

/usr/local/php/sbin/php-fpm start

注:/usr/local/php/sbin/php-fpm还有其他参数,包括:start|stop|quit|restart|reload|logrotate,修改php.ini后不重启php-cgi,重新加载配置文件使用reload。

5、安装编译nginx

5.1安装Nginx所需的pcre库:

tar zxvf pcre-7.9.tar.gz

cd pcre-7.9/

./configure

make && make install

5.2安装Nginx

tar zxvf nginx-0.8.15.tar.gz

cd nginx-0.8.15/

./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

make && make install

5.3建Nginx配置文件

在/usr/local/nginx/conf/目录中创建nginx.conf文件:

在/usr/local/nginx/conf/目录中创建fcgi.conf文件:

5.4启动Nginx

ulimit -SHn 65535

/usr/local/nginx/sbin/nginx

5.5配置开机自动启动Nginx + PHP

vi /etc/rc.local

ulimit -SHn 65535

/usr/local/php/sbin/php-fpm start

/usr/local/nginx/sbin/nginx

5.6优化Linux内核参数

vi /etc/sysctl.conf

# Add

net.ipv4.tcp_max_syn_backlog = 65536

https://www.wendangku.net/doc/f1231196.html,dev_max_backlog = 32768

net.core.somaxconn = 32768

net.core.wmem_default = 8388608

net.core.rmem_default = 8388608

net.core.rmem_max = 16777216

net.core.wmem_max = 16777216

net.ipv4.tcp_timestamps = 0

net.ipv4.tcp_synack_retries = 2

net.ipv4.tcp_syn_retries = 2

net.ipv4.tcp_tw_recycle = 1

#net.ipv4.tcp_tw_len = 1

net.ipv4.tcp_tw_reuse = 1

net.ipv4.tcp_mem = 94500000 915000000 927000000

net.ipv4.tcp_max_orphans = 3276800

#net.ipv4.tcp_fin_timeout = 30

#net.ipv4.tcp_keepalive_time = 120

net.ipv4.ip_local_port_range = 1024 65535

使配置立即生效:

/sbin/sysctl –p

5.7在不停止Nginx服务的情况下平滑变更Nginx配置

5.7.1修改/usr/local/nginx/conf/nginx.conf配置文件后,请执行以下命令检查配置文件是否正确:

/usr/local/nginx/sbin/nginx -t

如果屏幕显示以下两行信息,说明配置文件正确:

the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

the configuration file /usr/local/nginx/conf/nginx.conf was tested successfully

5.7.2这时,输入以下命令查看Nginx主进程号:

ps -ef | grep "nginx: master process" | grep -v "grep" | awk -F ' ' '{print $2}'

屏幕显示的即为Nginx主进程号,例如:

6302

这时,执行以下命令即可使修改过的Nginx配置文件生效:

kill -HUP 6302

或者无需这么麻烦,找到Nginx的Pid文件:

kill -HUP `cat /usr/local/nginx/nginx.pid`

5.8编写每天定时切割Nginx日志的脚本

5.8.1创建脚本/usr/local/nginx/sbin/cut_nginx_log.sh

输入以下内容:

############################################################

#!/bin/bash

# This script run at 00:00

# The Nginx logs path

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`

############################################################

5.8.2设置crontab,每天凌晨00:00切割nginx访问日志

crontab -e

输入以下内容:

00 00 * * * /bin/bash /usr/local/nginx/sbin/cut_nginx_log.sh

6 安装编译memcached

6.1、安装libevent(Memcache用到了libevent这个库用于Socket的处理,所以还需要安装libevent)

下载地址:https://www.wendangku.net/doc/f1231196.html,/~provos/libevent/

安装位置:/usr/local/libevent (根据自己喜好而定,建议外部程序库都装到/usr/local对应的目录下)

安装过程:

#下载解压

$ wget https://www.wendangku.net/doc/f1231196.html,/~provos/libevent-1.4.10-stable.tar.gz (请在安装时选择最新稳定版) $ tar -xvf libevent-1.4.10-stable.tar.gz

$ cd libevent-1.4.10-stable

#安装

$ ./configure --prefix=/usr/local/libevent

$ make

$ make install

# 建立libevent-1.4.so.2到/usr/lib的软连接,这样memcached运行的时候才能找到libevent 库

ln -s /usr/local/lib/libevent-1.4.so.2 /lib/libevent-1.4.so.2

6.2、安装memcached

下载地址:https://www.wendangku.net/doc/f1231196.html,/memcached/download.bml

安装位置:/usr/local/memcached (根据自己喜好而定,建议外部程序库都装到/usr/local对应的目录下)

安装过程:

#下载解压

$ wget https://www.wendangku.net/doc/f1231196.html,/files/memcached-1.2.8.tar.gz(请在安装时选择最新稳定版)

$ tar -xvf memcached-1.2.8.tar.gz

$ cd memcached-1.2.8

#安装

$ ./configure --prefix=/usr/local/memcached -with-libevent=/usr/local/libevent

$ make

$ make install

6.3、启动memcached守护进程

$ /usr/local/memcached/bin/memcached -d -m 64 -u root -l 127.0.0.1 -p 11211 -c 256 -P /tmp/memcached.pid

-d 启动一个守护进程

-m 限制内存大小,以M为单位,默认64M

-l 监听的服务器IP

-p 监听的端口,默认11211

-c 并发连接数,默认是1024

-P 保存进程编号的文件

判断是否成功可以ps -aux|gerp 'memcached' 或者cat /tmp/memcached.pid

memcached支持的参数可以通过memcached -h列出,具体作用见其后面的解释6.4、php使用测试

$mem = new Memcache;

$mem->connect('127.0.0.1', 11211);

$mem->set('key', 'this is a test', 0, 60);

$val = $mem->get('key');

echo $val;

?>

$ vi mtest.php (输入上述内容)

$ /usr/local/php/bin/php mtest.php (如果能输出“this is a test”, 表示测试成功) 6.5、停止memcached服务

$ kill -9 `cat /tmp/memcached.pid`(不是单引号,是~键下面的那个符号)

Windows下Nginx的安装与配置

Windows下Nginx的安装与配置 Windows下Nginx的安装与配置 Nginx ("engine x") 是一款高性能的,轻量级的HTTP Web服务器和反向代理服务器及电子邮件IMAP/POP3/SMTP代理服务器。 Nginx是由俄罗斯的程序设计师Igor Sysoev 所开发,为俄罗斯访问量第二的Rambler.ru 站点开发的,它已经在该站点运行超过四年多时间了,Igor 将源代码以类BSD许可证的形式发布。 自Nginx 发布四年来,Nginx 已经因它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名了。Nginx 超越Apache的高性能和稳定性,使得国内使用Nginx 作为Web 服务器的网站也越来越多。 目前国内各大门户网站已经部署了Nginx,如新浪、网易、腾讯等;新近发现Nginx 技术在国内日趋火热,越来越多的网站开始应用部署Nginx。 一、首先去官网下载nginx1.0.11的Windows版本,官网下载: https://www.wendangku.net/doc/f1231196.html,/download/nginx-1.0.11.zip 下载到软件包后,解压nginx-nginx1.0.11.zip 包到你喜欢的根目录,并将目录名改为nginx。 然后,执行下列操作: cd nginx start nginx 这样,nginx 服务就启动了。打开任务管理器,查看nginx.exe 进程,有二个进程会显示,占用系统资源,那是相当的少。然后再打开浏览器,输入http://127.0.0.1/就可以看到nginx 的欢迎页面了,非常友好 nginx -s stop // 停止nginx nginx -s reload // 重新加载配置文件 nginx -s quit // 退出nginx 二、接下来就是配置nginx的conf文件了。下面是我的配置: #user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid;

rtmp流媒体协议

H5视频直播扫盲 1 H5到底能不能做视频直播 当然可以, H5火了这么久,涵盖了各个方面的技术。 对于视频录制,可以使用强大的webRTC(Web Real-Time Communication)是一个支持网页浏览器进行实时语音对话或视频对话的技术,缺点是只在PC的chrome上支持较好,移动端支持不太理想。 对于视频播放,可以使用HLS(HTTP Live Streaming)协议播放直播流,ios和android都天然支持这种协议,配置简单,直接使用video标签即可。 webRTC兼容性: video标签播放hls协议视频:

1 2 3 4

Your browser does not support HTML5 video. 2 到底什么是HLS协议 简单讲就是把整个流分成一个个小的,基于HTTP的文件来下载,每次只下载一些,前面提到了用于H5播放直播视频时引入的一个.m3u8的文件,这个文件就是基于HLS协议,存放视频流元数据的文件。 每一个.m3u8文件,分别对应若干个ts文件,这些ts文件才是真正存放视频的数据,m3u8文件只是存放了一些ts文件的配置信息和相关路径,当视频播放时,.m3u8是动态改变的,video标签会解析这个文件,并找到对应的ts文件来播放,所以一般为了加快速度,.m3u8放在web服务器上,ts文件放在cdn上。 .m3u8文件,其实就是以UTF-8编码的m3u文件,这个文件本身不能播放,只是存放了播放信息的文本文件: 1 2 3 4 5#EXTM3U m3u文件头 #EXT-X-MEDIA-SEQUENCE 第一个TS分片的序列号#EXT-X-TARGETDURATION 每个分片TS的最大的时长#EXT-X-ALLOW-CACHE是否允许cache #EXT-X-ENDLISTm3u8文件结束符

在centos上搭建nginx图片服务器(包含上传模块)

安装Nginx 和相关的插件 (Image Filter Module & Upload Module & Upload Progress Module) (1) install essential sys library $ yum -y install gcc-c++ $ yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel gd gd-devel (2)install nginx & related module plugin $ wget https://https://www.wendangku.net/doc/f1231196.html,/masterzen/nginx-upload-progress-module/archive/v0.9.1.tar.gz $ wget https://https://www.wendangku.net/doc/f1231196.html,/vkholodkov/nginx-upload-module/archive/2.2.0.tar.gz $ wget https://www.wendangku.net/doc/f1231196.html,/download/nginx-1.3.8.tar.gz $ tar zxvf *.tar.gz $ cd /nginx-1.3.8/conf (3)configure nginx.conf $ vi nginx.conf #user root; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"';

windows下搭建基于nginx的rtmp服务器

windows下搭建基于nginx的rtmp服务器 Windows机器配置:Windows7旗舰版64位Intel(R) Core(TM)i5-2520 CPU @2.50GHz 2.50 GHz内存: 4GB1. 下载nginx 1.7.11.3 Gryphon下载链接: http://nginx-win.ecsds.eu/download/nginx 1.7.11.3 Gryphon.zip 下载完成后解压;将解压后的目录名: nginx 1.7.11.3 Gryphon改成: nginx-1.7.11.3-Gryphon2. 下载服务器状态检查程序stat.xslhttps://https://www.wendangku.net/doc/f1231196.html,/arut/nginx-rtmp-module/将nginx-rtmp-module-master.zip解压后复制到目 录:nginx-1.7.11.3-Gryphon下,保证stat.xls的目录 为:nginx-1.7.11.3-Gryphon\nginx-rtmp-module\stat.xsl3. 配置文件conf\nginx-win-rtmp.conf 内容如下:#user nobody;# multiple workers works !worker_processes 2;#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;#pid logs/nginx.pid;events { worker_connections 8192; # max value 32768, nginx recycling connections+registry optimization = # this.value * 20 = max concurrent connections currently tested with one worker # C1000K should be possible depending there is enough ram/cpu power # multi_accept on;}rtmp { server { listen 1935;

课题_nginx搭建rtmp协议流媒体服务器总结

nginx搭建rtmp协议流媒体服务器总结 最近在ubuntu12.04上搭建了一个rtmp服务器,感觉还挺麻烦的,所以记录下。 大部分都是参考网络上的资料。 前提: 在linux下某个目录中新建一个nginx目录。 然后进入该目录去下载搭建环境所需要的一些资源包。 此处在/root/ 目录下新建一个nginx目录即: /root/nginx/ ==================================== 1、安装依赖包: #yum -y install gcc glibc glibc-devel make nasm pkgconfig lib-devel openssl-devel expat-devel gettext-devel libtool mhash.x86_64 perl-Digest-SHA1.x86_64 2、安装相关工具包 1). git # mkdir soft-source # cd soft-source # wget ://https://www.wendangku.net/doc/f1231196.html,/projects/git-snapshots/git/git-latest.tar.xz # xz -d git-latest.tar.xz # tar xzvf git-latest.tar # cd git-2014-06-27 # autoconf # ./configure # make && make install # git --version git version 2.0.0.GIT # cd .. 2). zlib # wget ://https://www.wendangku.net/doc/f1231196.html,/zlib-1.2.8.tar.gz # tar -zxvf zlib-1.2.8.tar.gz cd zlib-1.2.8 # ./configure # make # make install # cd .. 3). pcre # wget ://exim.mirror.fr/pcre/pcre-8.12.tar.gz # tar zxvf pcre-8.12.tar.gz # cd pcre-8.12 # ./configure # make && make install # cd .. 4). yadmi yadmi的作用是为flv文件添加关键帧,才能实现拖动播放 # wget ://https://www.wendangku.net/doc/f1231196.html,/projects/yamdi/files/yamdi/1.4/yamdi-1.4.tar.gz/download # tar xzvf download # cd yamdi-1.4 # make && make install # cd .. 使用方法: # yamdi -i input.flv -o out.flv 给input.flv文件添加关键帧,输出为out.flv文件 5). OpenSSL # wget ://https://www.wendangku.net/doc/f1231196.html,/source/openssl-1.0.1c.tar.gz # tar -zxvf openssl-1.0.1c.tar.gz # ./config # make # make install 3、安装ffmpeg及其依赖包: 1). Yasm # wget ://https://www.wendangku.net/doc/f1231196.html,/projects/yasm/releases/yasm-1.2.0.tar.gz # tar xzvf yasm-1.2.0.tar.gz

nginx配置解析详解(一)

nginx配置解析详解(一) 现在针对nginx源码分析的blog和文章已经很多了,之前我也看过不少,大家的分析都很不错。太多重复的内容就不写了,主要想针对在我分析代码和查阅blog的过程中,发现的一些比较晦涩或者某些细节有待展开讨论的地方,给出我的自己理解和看法,希望跟大家交流和学习。 使用的nginx版本是nginx-1.0.6,我最开始看的代码是0.7.62,新的版本在功能和稳定性上做了很多的工作。在分析的时候,我尽量简单明了,不太重要的地方一带而过,具体地大家可以去读代码。相对复杂或者晦涩的地方,将详细展开。 首先我们从配置文件开始,下面的分析是建立在网友对nginx的配置文件结构有大概熟悉为前提,这样才可以很好的理解代码。这里有必要提醒一点:原始代码目录中 ngx_modules这个结构,是找不到它的定义和初始化,要看到它,你必须执行configure,make,在原来的代码目录下会出现一个objs文件夹,里面的3个文件ngx_auto_config.h,ngx_auto_headers.h,ngx_modules.c,需要在建source insight工程时也包含进去,这样有利于我们把握整个代码结构。有意思的是,nginx的configure文件是作者手工写的,里面有许多管理代码工程的方法,有时间的话,也是值得学习下的。 1.ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle); 配置文件的解析相关的处理主要在ngx_init_cycle函数中被调用。既然如此,我们就先说说ngx_init_cycle函数吧。 它需要一个参数类型为ngx_cycle_t *,返回值也是一个ngx_cycle_t*,与此同时我们注意到参数名为old_cycle,那么这个函数的作用是啥呢?很明显是由old得到一个new。其中ngx_cycle_t的结构保存一些全局的配置和信息。 这个函数具体作用将在reconfig(重读配置文件)的时候得到体现,可以理解为old_cycle 是当前正在使用的配置信息,当配置文件做了某些修改之后,ngx_init_cycle通过old_cycle 中的一些数据,对new_cycle进行一些设置,在经过进一步的配置解析之后,就可以得到一个new cycle。 2.char *ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename) 当我们使用sourceinsight查看这个函数的调用情况时,会发现调用它的地方很多。其实,入口点就在ngx_init_cycle中对ngx_conf_parse调用,后面的所有的调用可以看作是在此之后的递归调用。为什么会是这个样子呢?原因在于nginx是一边读取配置信息,一边解析执行相关的处理,具体一点讲,就是“读一行,执行一行”,一行的定义在这里是指以分号或者是“{”和“}”等结尾的一行,例如:我们解析到http {},我们就调用针对httpblock的处理,在处理的时候我们又会碰到server {},自然就会调用server block的处理。。。以此类推!。

Windows下编译Nginx并添加模块

Windows下编译Nginx并添加模块 一.准备工作 1.环境安装 1.安装vs2010或vs2013等vs工具。 2.安装ActivePerl,安装完成后,将其安装路径加入到PATH环境变量。 3.安装MinGW,下载mingw-get-setup.exe,安装完成后,将其安装路径加入到PATH环境变量。(记得安装的时候装上msys,不懂就全勾了) 4.安装nasm,安装完成后,将其安装路径加入到PATH环境变量。 2.下载编译nginx源码文件 1.nginx源码:nginx-1.1 2.2 2.pcre:pcre-8.40 3.zlib:zlib-1.2.11 4.openssl:openssl-1.0.2l 3.下载添加模块文件 1.文件上传模块: nginx-upload-module 2.rtmp模块:nginx-rtmp-module 3.文件上传进度条模块:nginx-upload-progress-module 二.编译并添加模块 1.将上述7个压缩包文件解压至文件夹msys文件目录下,如C:\MinGW\msys\1.0\home\$UESRNAME\。 2.找到msys.bat的路径并双击msys.bat,运行。如下图所示

3.打开msys.bat后如下所示 右击上方编辑栏,选择编辑,粘贴,可进行粘贴复制功能。 4.cd 至nginx源码路径,并在源码路径下执行下面语句: auto/configure --with-cc=cl --builddir=objs --prefix= \ --conf-path=conf/nginx.conf --pid-path=logs/nginx.pid \ --http-log-path=logs/access.log --error-log-path=logs/error.log \ --sbin-path=nginx.exe --http-client-body-temp-path=temp/client_body_temp \ --http-proxy-temp-path=temp/proxy_temp \ --http-fastcgi-temp-path=temp/fastcgi_temp \ --with-cc-opt=-DFD_SETSIZE=1024 --with-pcre=../pcre-8.40 \ --with-zlib=../zlib-1.2.11 --with-openssl=../openssl-1.0.2l \ --with-select_module --with-http_ssl_module \ --with-http_sub_module \ --add-module=../nginx-upload-module-2.255 \ --add-module=../nginx-upload-progress-module-master \ --add-module=../nginx-rtmp-module-master \ 其中pcre,zlib,openssl的语句需根据版本号的不同进行改变,最后增加的模块也需更具实际情况进行相应的改变,步骤4操作如下图所示:

linux下Nginx+tomcat整合的安装与配置

linux下Nginx+tomcat整合的安装与配置 目的:搭建Nginx与tomcat整合,用Nginx代替apache 步骤: 一、安装Tomcat和JDK 1、上传apache-tomcat-6.0.18.tar.gz和jdk-6u12-linux-i586.bin至/usr/local 2、执行如下命令安装tomcat: 查看 打印? 1. 2.#cd /usr/local 3.#tar zxvf apache-tomcat-6.0.18.tar.gz 解压完成后将apache-tomcat-6.0.18重命名为tomcat 3、执行如下命令安装JDK: 查看 打印? 1. 2.#./jdk-6u12-linux-i586.bin 4、配置环境变量: 编辑/etc下的profile文件,加上如下内容: 查看 打印? 1. 2.JAVA_HOME="/usr/local/jdk1.6.0_12" 3.CLASS_PATH="$JAVA_HOME/lib:$JAVA_HOME/jre/lib" 4.PATH=".:$PATH:$JAVA_HOME/bin " 5. 6.CATALINA_HOME="/usr/local/tomcat" 7.export JAVA_HOME CATALINA_HOME 5、启动tomcat并输入http://localhost:8080,如果看到猫的页面即tomcat和jdk安装成功 6、新建文件目录/home/www为网站存放目录,设置server.xml文件,在Host name="localhost"处将appBase=的指向路径改为/home/www/web

Nginx与PHP(FastCGI)的安装、配置与优化

Nginx与PHP(FastCGI)的安装、配置与优化 FastCGI的介绍和工作原理 首先简单的介绍下FastCGI: FastCGI是语言无关的、可伸缩结构的CGI开放扩展,其主要行为是将CGI解释器进行保持在内存中并因此获得较高的性能。众所周知,CGI解释器的反复加载是CGI性能低下的主要原因,如果CGI解释器保持在内存中并接受FastCGI进程管理器调度,则可以提供良好的性能、伸缩性、Fail-Over特性等。 FastCGI的工作原理是: (1)FastCGI进程管理器自身初始化,启动多个CGI解释器进程(多个php-cgi进程)并等待来自Web Server的连接。在文本中,采用PHP-FPM进程管理器启动多个php-cgi FastCGI进程。启动php-cgi FastCGI进程时,可以配置以TCP和UNIX套接字两种方式启动。 (2)当客户端请求达到Web服务器(Nginx)时,Web服务器将请求采用TCP协议或UNIX 套接字方式转发到FastCGI主进程,FastCGI主进程选择并连接到一个CGI解释器(子进程)。Web服务器将CGI环境变量和标准输入发送到FastCGI子进程php-cgi。 (3)FastCGI子进程完成处理后将标准输出和错误信息从同一连接返回Web服务器(Nginx)。当FastCGI子进程关闭连接时,请求便告知处理完成。FastCGI子进程接着等待并处理来自FastCGI进程管理的下一个连接。而在一般的普通CGI模式中,php-cgi在此便退出了。 PHP-FPM PHP-FPM是一个PHP FastCGI管理器,是只用于PHP的,可以在 https://www.wendangku.net/doc/f1231196.html,/downloads.php下载得到.PHP-FPM其实是PHP源代码的一个补丁,旨在将FastCGI进程管理整合进PHP包中。必须将它patch到你的PHP源代码中,在编译安装PHP后才可以使用。

Nginx-1.0.15负载均衡安装配置

nginx-1.0.15负载均衡安装配置 OS:ubuntu 1、取得软件 pcre-8.30.zip nginx-1.0.15.tar.gz apt-get install gcclibpcre*zlib 2、安装rewrite的支持库pcre unzip pcre-8.30.zip cd pcre-8.30 ./configure make make install 3、配置nginx.conf cat /usr/local/nginx/conf/nginx.conf | grep -Ev '(#|^$)' worker_processes 1; events { worker_connections 1024; } http { includemime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; upstream https://www.wendangku.net/doc/f1231196.html, { server 10.0.0.252:8080; server 10.0.0.253:8080; server 10.0.0.105:8080; } server { listen 80; server_name https://www.wendangku.net/doc/f1231196.html,; location ~ ^/$ { rewrite ^/(.*) /jboss/ break; proxy_pass https://www.wendangku.net/doc/f1231196.html,; } } }

4、启动nginx服务 /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

linux nginx搭建

1.安装nginx 1.解压安装包 分别解压nginx,pcre,openss,nginx-rtmp-module,nginx_mod_h264_streaming到/root/work/nginx_download目录下,进入nginx解压后的目录nginx-1.6.2 2.安装nginx ./configure\ --prefix=/root/work/nginx_download/nginx\ --with-pcre=../pcre-8.36\ --with-http_stub_status_module\ --with-http_ssl_module\ --add-module=../nginx_mod_h264_streaming-2.2.7\ --add-module=../nginx-rtmp-module-master\ --with-debug --with-openssl=../openssl-1.0.1 j make && make install 安装成功后,/root/work/nginx_download/nginx\下会有相关软件生成 出错解决方法:https://www.wendangku.net/doc/f1231196.html,/vblittleboy/article/details/40616405 3.配置nginx 请将文件安装包\nginx\配置文件\nginx_rtmp.conf 拷贝到nginx/conf下 4.启动nginx ./sbin/nginx -c conf/nginx_rtmp.conf 正常运行后,可以发现有三个nginx进程 5.推流

利用ffmpeg可以将视频文件已rtmp格式推送到nginx服务器中。 推送流命令如下:./ffmpeg -re -i 7.mp4 -c copy -f flv rtmp://192.168.1.102/hls/1 6.观看效果 在/tmp/app下存在切片生成的ts流,通过hls协议就可以以点播的形式实现直播技术。 可以在pc上以及安卓系统中通过rtmp协议观看。 也可以在ios系统上通过hls协议观看。 相比,hls协议观看延迟要大些,大概延迟在1分钟左右。

【Nginx服务器的编译安装与配置】 安装配置服务器失败

【Nginx服务器的编译安装与配置】安装配置服务器失败 Nginx 是一个很强大的轻量级、高性能Web和反向代理服务器,由俄罗斯人开发而成。它具有很多非常优越的特性:在高连接并发的情况下,Nginx是Apache服务器不错的替代品。而且还可以作为负载均衡服务器,代码用C语言完成,运行效率非常高,还可以做邮件代理服务器。下面是小编跟大家分享的是Nginx服务器的编译安装与配置,欢迎大家来阅读学习~ Nginx服务器的编译安装与配置 工具/原料 Linux服务器或虚拟机一台(这里使用的CentOS6.5) Nginx源码包(这里使用1.44的版本,下载链接:H://pan.baidu/s/1qWoe2te 密码:fqji) 方法/步骤 1要编译安装Nginx,首先我们要安装依赖包pcre-devel 和zlib-devel: # yum install pcre-devel zlib-devel -y 程序默认是使用nobody 身份运行的,我们建议使用nginx 用户来运行,首先添加Nginx组和用户,不创建家目录,不允许登陆系统 # groupadd nginx # useradd -M -s /sbin/nologin -g nginx nginx

2准备工作完成后就是下载编译安装Nginx了,可以从我提供的网盘下载,也可以去Nginx的官网下载。 首先解压源码包: # tar xf nginx-1.4.4.tar.gz 然后cd 到解压后的目录就可以执行./configure 了 # cd nginx-1.4.4 指定安装目录和运行时用的属主和属组,并启用状态监控模块等 # ./configure \ --prefix=/usr/local/nginx \ --pid-path=/var/run/nginx/nginx.pid \ --lock-path=/var/lock/nginx.lock \ --user=nginx \ --group=nginx \ --with-H_ssl_module \ --with-H_flv_module \

nginx负载均衡master配置文件nginx.conf

#user nobody; worker_processes auto; #error_log logs/error.log; error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; worker_rlimit_nofile 100000; events { use epoll; worker_connections 204800; } http { ## 用户的IP 地址$binary_remote_addr 作为Key,每个IP 地址最多有50 个并发连接 ## 你想开几千个连接刷死我?超过50 个连接,直接返回503 错误给你,根本不处理你的请求了 limit_conn_zone $binary_remote_addr zone=TotalConnLimitZone:10m ; #limit_conn TotalConnLimitZone 50; limit_conn TotalConnLimitZone 500; limit_conn_log_level notice; ## 用户的IP 地址$binary_remote_addr 作为Key,每个IP 地址每分钟处理50 个请求## 你想用程序每秒几百次的刷我,没戏,再快了就不处理了,直接返回503 错误给你 #limit_req_zone $binary_remote_addr zone=ConnLimitZone:10m rate=200r/m; limit_req_zone $binary_remote_addr zone=ConnLimitZone:10m rate=2000r/m; limit_req_log_level notice; #include mime.types; #default_type application/octet-stream; #access_log logs/access.log main; #server_tokens off; #sendfile on; #tcp_nopush on; #keepalive_timeout 0; #keepalive_timeout 65; server_tokens off; include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] $request ' '"$status" $body_bytes_sent "$http_referer" '

在腾讯云服务器上搭建 Nginx 静态网站的详细步骤

搭建Nginx 静态网站的详细步骤 【注意事项】:如果以前安装了HTTPS或者微信小程序环境,以下步骤不能正常完成静态网站的搭建。建议在开始以下步骤之前,先备份好数据,然后重新安装操作系统(最省事、最简单的办法)。 1、搭建Http静态服务器环境 搭建静态网站,首先需要部署环境。下面的步骤,将告诉大家如何在服务器上通过 Nginx 部署 HTTP 静态服务。 1.1、安装Nginx 在 CentOS 上,可直接使用 yum 来安装 Nginx #yum install nginx -y 安装完成后,使用 nginx 命令启动 Nginx: #nginx 此时,访问 http://119.29.169.38 可以看到 Nginx 的测试页面 1.2、配置静态服务器访问路径 外网用户访问服务器的 Web 服务由 Nginx 提供,Nginx 需要配置静态资源的路径信息才能通过 url 正确访问到服务器上的静态资源。 打开 Nginx 的默认配置文件 /etc/nginx/nginx.conf ,修改 Nginx 配置,将默认的 root /usr/share/nginx/html; 修改为: root /data/www;,如下:nginx.conf(文件内容略) 配置文件将 /data/www/static 作为所有静态资源请求的根路径,如访问: http://119.29.169.38/static/index.js,将会去 /data/www/static/ 目录下去查找 index.js。现在我们需要重启 Nginx 让新的配置生效,如:#nginx -s reload

1.1 nginx部署(单机)-手动安装

注: 在配置时,建议使用非root用户配置,本文档以【用户密码:nginx/nginx】【目录:/nginx】为例进行说明 文档中执行命令为蓝色字体;配置文件为粉色字体;重点标记为红色字体 1.单机部署 1.1.准备 上传【1.1 nginx部署介质.zip】包到安装目录/nginx,执行解压得到soft目录 unzip 1.1\nginx部署介质.zip 1.2.安装 1.2.1.解压依赖库 cd /nginx/soft &&tar -zxvf pcre-8.35.tar.gz&&tar -zxvf zlib-1.2.8.tar.gz&&tar -zxvf openssl-1.0.1c.tar.gz 1.2.2.安装nginx cd /nginx/soft&&tar -xvfnginx-1.11.5.tar.gz&&cd nginx-1.11.5&&./configure --prefix=/nginx/nginx--with-pcre=/nginx/soft/pcre-8.35 --with-zlib=/nginx/soft/zlib-1.2.8 --with-openssl=/nginx/soft/openssl-1.0.1c&&make&&make install 安装之后soft目录不能删除! 1.2.3.验证 进入/nginx/nginx,出现以下4个目录conf、html、logs、sbin 1.3.配置 1.3.1.修改配置nginx.conf文件 cd/nginx/nginx/conf vi nginx.conf 删除原来所有内容,使用以下内容,或者复制soft下面nginx.conf至此目录,然后进行修改

Linux系统服务器Nginx配置404页面的方法

Linux系统服务器Nginx配置404页面的方法 Linux系统环境下Nginx配置404页面很多设置后返回状态码是200,而不是404状态码,所以那样的404页面设置是不正确的,今天分享下Linux下Nginx配置404页面设置方法: 按照以下5步骤: 1、创建自己的404.html页面,并放于网站根目录; 2、更改nginx.conf在http定义区域加入: vi /usr/local/nginx/conf/nginx.conf 编辑Nginx配置文件,在http 区段添加下面代码:fastcgi_intercept_errors on; 3、更改nginx.conf 在网站配置中在server 区域加入: 1. 2.server{ 3.error_page 404 = 40 4.html; #只是转跳而已 4.}

网上教程基本都是使用上面代码,返回的是200状态码,正确的设置是去掉=,如下代码所示: 1. 2.server{ 3.error_page 404 40 4.html; 4.} 4、测试nginx.conf正确性: 1./usr/local/nginx/sbin/nginx –t 返回下面代码通过: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok configuration file /usr/local/nginx/conf/nginx.conf test is successful 5、平滑重启Nginx,即可解决完成404页面设置。 1./usr/local/ws/nginx/sbin/nginx -s reload 这样在用站长工具测试状态码,检测的状态码就是404了,也就完成了Linux下Nginx配置404页面设置。 相关说明:当用户进入https://www.wendangku.net/doc/f1231196.html,,点击了一个不存在或者已经删除的页面,网站会出现该页面不存在的提示,很多网站返回的是200状态码,而不是能引导用户返回。

Nginx高级配置

Nginx高级配置 1. Nginx连接后端的方式:反向代理(proxy_pass)、直连 fastcgi(fastcgi_pass) 例子: fastcgi_pass backend1; proxy_pass http://backend2; location块中配置此项,表示用反向代理或直连fastcgi的方式连接后端服务,其中backend1、backend2为upstream配置,其中配置下游的ip&port列表和调度参数,见下文。 注意:fastcgi_pass与proxy_pass是互斥配置,不能同时生效。 2. Nginx调度与负载均衡配置(upstream 配置) 1) 轮询(默认)每个请求按时间顺序逐一分配到不同的后端服务器。weight指定轮询几率,weight和访问比率成正比,用于后端服务器性能不均的情况,weight默认值为1。 例如: upstreambakend { server 192.168.0.14 weight=10; server 192.168.0.15 weight=10; } 2) ip_hash 每个请求按访问ip的hash结果分配,这样每个访客固定访问一个后端服务器,可以解决session的问题。 例如: upstreambakend { ip_hash; server 192.168.0.14:88; server 192.168.0.15:80; } 3) hash 每个请求按访问$hash_seed的hash结果分配。 例如: upstreambakend { hash $hash_seed; server 192.168.0.14:88; server 192.168.0.15:80;

nginx完美架构方案

北京闻康集团 有问必答架构调整方案及实施过程(高性能W E B系统) 侯在存 2010年12月

第1章调整方案概述 1.1 总体概述 项目目的出现灾难迅速恢复,让服务器的对外提供达到99.9%. 项目负责人侯在存 涉及机房三元桥东四廊坊 涉及设备DELL R710 2950 预计时间六个月 项目阶段 1.数据库应用分离 2.nginx对apache的替换3.增加memcache 需增设备2台 DELL 服务器和部分内存条(现有一台空闲服务器)项目简述: 项目前:club服务器有5台名字分https://www.wendangku.net/doc/f1231196.html, ,每台服务器跑的是AMP+nginx反向代理和负载均衡+DNS轮询及rsync程序同步,其中的mysql都是从的(读的数据库),另外还有一台是主数据198(写的)+ 一台备份数据库做冗余205(且分担蜘蛛抓取)。 注:c1 c2 在三元桥 c3 c4在廊坊 c5在东单 项目后:三元桥的C1C2和新增的1台服务器承担所有的访问,c3 c4 c5不对外提供访问,做 c1 c2服务器出现问题时的恢复冗余机和蜘蛛抓取承担,所有的mysql也停用做冗余用,增加一台读的数据库让 club服务器的读数据库都改到这台服务器上,原来的198不变但需要增加内存。例外+一台读写数据库服务器的同步冗余机,从而实现服务器出现大灾难2小时内解决,小灾难半小时解决,让服务器的对外提供达到99.9%. 注:nginx+phpcgi代替amp 及对c1 c2 的优化可以使三元桥WEB承载所有的访问。 项目影响: 由于本次将服务器的web服务替换,ssi和rewrite规则支持不一样,业务可能会中断,需某周5到-周日的修改。

NGinx分布式部署测试实例图解

https://www.wendangku.net/doc/f1231196.html,+Mvc+NGinx+IIS分布式部署和负载平衡实例图解 目的:在IIS中创建四个相同的网站,浏览器访问同一个地址,通过NGinx转到不同的IIS 网站。 测试条件: Windows 7 X64旗舰版+Visual Studio 2017专业版 1、创建https://www.wendangku.net/doc/f1231196.html, +Mvc WebApplication 在VS运行后的页面效果如下:

2、发布网站 3、IIS中部署四个网站 创建三个应用程序池,端口分别为: 8001、8002、8003,8004分别对应四个网站。 为区分三个网站,把Index.cshtml文件中的“Nginx测试程序”这行字分别改为:Nginx测试程序--------1 Nginx测试程序--------2 Nginx测试程序--------3 Nginx测试程序--------4 如下图: 部署四个网站后,打开页面效果如下:

到此,说明四个网站部署后单独访问都没有问题。下面开始部署NGInx的负载平衡。

4、NGInx的安装 4.1、下载nginx-1.1 5.1 下载后解压到D:\nginx文件夹,解压后的文件夹如下: 4.2、修改配置文件nginx.conf nginx.conf文件位于D:\nginx\conf目录下,nginx.conf默认内容如下。用记事本打开文件,nginx.conf文件的内容如下: #user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" '

相关文档
相关文档 最新文档