如何架设Nginx+Php Web服务器
2个回答
展开全部
Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,它已经在该站点运行超过两年半了。Igor 将源代码以类BSD许可证的形式发布。尽管还是测试版,但是,Nginx 已经因为它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名了。
本文是W3CGROUP在成功架设Nginx+Php Web服务器之后的一个总结,成功设置Nginx开启多域名多站点,并且不会出现502 Bad Gateway错误!
本文测试环境如下:
系统环境
Linux version 2.6.9(CentOS release 4.7(Final))
软件环境
nginx-0.6.35.tar.gz
安装步骤
一、 编译安装PHP5.2.9所需的支持库
tar zxvf libiconv-1.13.tar.gzcd libiconv-1.13/./configure --prefix=/usr/localmakemake installcd ../
tar zxvf libmcrypt-2.5.8.tar.gzcd libmcrypt-2.5.8/./configuremakemake install/sbin/ldconfigcd libltdl/./configure --enable-ltdl-installmakemake installcd ../../
tar zxvf mhash-0.9.9.9.tar.gzcd mhash-0.9.9.9/./configuremakemake installcd ../
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.laln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.soln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.aln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.laln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.soln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
tar zxvf mcrypt-2.6.8.tar.gzcd mcrypt-2.6.8//sbin/ldconfig./configuremakemake installcd ../
二、编译安装MySQL 5.1.34扩展库
/usr/sbin/groupadd mysql/usr/sbin/useradd -g mysql mysqltar zxvf mysql-5.1.34.tar.gzcd mysql-5.1.34/./configure --prefix=/usr/local/webserver/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=innobasemake && make installchmod +w /usr/local/webserver/mysqlchown -R mysql:mysql /usr/local/webserver/mysqlcd ../
MySql的安装此处就省略
三、编译安装PHP(FastCGI模式)
tar zxvf php-5.2.9.tar.gzgzip -cd php-5.2.9-fpm-0.5.10.diff.gz | patch -d php-5.2.9 -p1cd php-5.2.9/./configure --prefix=/usr/local/webserver/php --with-config-file-path=/usr/local/webserver/php/etc --with-mysql=/usr/local/webserver/mysql --with-mysqli=/usr/local/webserver/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-saslmake ZEND_EXTRA_LIBS='-liconv'make installcp php.ini-dist /usr/local/webserver/php/etc/php.inicd ../
四、修改php-fpm配置文件
rm -f /usr/local/webserver/php/etc/php-fpm.confvi /usr/local/webserver/php/etc/php-fpm.conf
输入以下内容:
<?xml version="1.0" ?><configuration><section name="global_options"><value name="pid_file">/usr/local/webserver/php/logs/php-fpm.pid</value><value name="error_log">/usr/local/webserver/php/logs/php-fpm.log</value><value name="log_level">notice</value><value name="emergency_restart_threshold">10</value><value name="emergency_restart_interval">1m</value><value name="process_control_timeout">5s</value><value name="daemonize">yes</value></section><workers><section name="pool"><value name="name">default</value><value name="listen_address">127.0.0.1:9000</value><value name="listen_options"><value name="backlog">-1</value><value name="owner"></value><value name="group"></value><value name="mode">0666</value></value><value name="php_defines"><value name="sendmail_path">/usr/sbin/sendmail -t -i</value><value name="display_errors">1</value></value><value name="user">www</value><value name="group">www</value><value name="pm"><value name="style">static</value><value name="max_children">128</value><value name="apache_like"><value name="StartServers">20</value><value name="MinSpareServers">5</value><value name="MaxSpareServers">35</value></value></value><value name="request_terminate_timeout">0s</value><value name="request_slowlog_timeout">0s</value><value name="slowlog">logs/slow.log</value><value name="rlimit_files">51200</value><value name="rlimit_core">0</value><value name="chroot"></value><value name="chdir"></value><value name="catch_workers_output">yes</value><value name="max_requests">500</value><value name="allowed_clients">127.0.0.1</value><value name="environment"><value name="HOSTNAME">$HOSTNAME</value><value name="PATH">/usr/local/bin:/usr/bin:/bin</value><value name="TMP">/tmp</value><value name="TMPDIR">/tmp</value><value name="TEMP">/tmp</value><value name="OSTYPE">$OSTYPE</value><value name="MACHTYPE">$MACHTYPE</value><value name="MALLOC_CHECK_">2</value></value></section></workers></configuration>
五、创建www用户组及www用户
/usr/sbin/groupadd www/usr/sbin/useradd -g www www
六、编译安装Nginx
tar zxvf nginx-0.6.35.tar.gzcd nginx-0.6.35/默认安装:./configuremake && make install默认情况下,Nginx 会被安装在 /usr/local/nginx。通过设定编译选项,你可以改变这个设定。
指定编译选项安装,如:./configure --user=www --group=www --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_modulemake && make installcd ../
七、创建fcgi.conf文件
rm -f /usr/local/webserver/nginx/conf/fcgi.confvi /usr/local/webserver/nginx/conf/fcgi.conf
本文是W3CGROUP在成功架设Nginx+Php Web服务器之后的一个总结,成功设置Nginx开启多域名多站点,并且不会出现502 Bad Gateway错误!
本文测试环境如下:
系统环境
Linux version 2.6.9(CentOS release 4.7(Final))
软件环境
nginx-0.6.35.tar.gz
安装步骤
一、 编译安装PHP5.2.9所需的支持库
tar zxvf libiconv-1.13.tar.gzcd libiconv-1.13/./configure --prefix=/usr/localmakemake installcd ../
tar zxvf libmcrypt-2.5.8.tar.gzcd libmcrypt-2.5.8/./configuremakemake install/sbin/ldconfigcd libltdl/./configure --enable-ltdl-installmakemake installcd ../../
tar zxvf mhash-0.9.9.9.tar.gzcd mhash-0.9.9.9/./configuremakemake installcd ../
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.laln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.soln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.aln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.laln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.soln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
tar zxvf mcrypt-2.6.8.tar.gzcd mcrypt-2.6.8//sbin/ldconfig./configuremakemake installcd ../
二、编译安装MySQL 5.1.34扩展库
/usr/sbin/groupadd mysql/usr/sbin/useradd -g mysql mysqltar zxvf mysql-5.1.34.tar.gzcd mysql-5.1.34/./configure --prefix=/usr/local/webserver/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=innobasemake && make installchmod +w /usr/local/webserver/mysqlchown -R mysql:mysql /usr/local/webserver/mysqlcd ../
MySql的安装此处就省略
三、编译安装PHP(FastCGI模式)
tar zxvf php-5.2.9.tar.gzgzip -cd php-5.2.9-fpm-0.5.10.diff.gz | patch -d php-5.2.9 -p1cd php-5.2.9/./configure --prefix=/usr/local/webserver/php --with-config-file-path=/usr/local/webserver/php/etc --with-mysql=/usr/local/webserver/mysql --with-mysqli=/usr/local/webserver/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-saslmake ZEND_EXTRA_LIBS='-liconv'make installcp php.ini-dist /usr/local/webserver/php/etc/php.inicd ../
四、修改php-fpm配置文件
rm -f /usr/local/webserver/php/etc/php-fpm.confvi /usr/local/webserver/php/etc/php-fpm.conf
输入以下内容:
<?xml version="1.0" ?><configuration><section name="global_options"><value name="pid_file">/usr/local/webserver/php/logs/php-fpm.pid</value><value name="error_log">/usr/local/webserver/php/logs/php-fpm.log</value><value name="log_level">notice</value><value name="emergency_restart_threshold">10</value><value name="emergency_restart_interval">1m</value><value name="process_control_timeout">5s</value><value name="daemonize">yes</value></section><workers><section name="pool"><value name="name">default</value><value name="listen_address">127.0.0.1:9000</value><value name="listen_options"><value name="backlog">-1</value><value name="owner"></value><value name="group"></value><value name="mode">0666</value></value><value name="php_defines"><value name="sendmail_path">/usr/sbin/sendmail -t -i</value><value name="display_errors">1</value></value><value name="user">www</value><value name="group">www</value><value name="pm"><value name="style">static</value><value name="max_children">128</value><value name="apache_like"><value name="StartServers">20</value><value name="MinSpareServers">5</value><value name="MaxSpareServers">35</value></value></value><value name="request_terminate_timeout">0s</value><value name="request_slowlog_timeout">0s</value><value name="slowlog">logs/slow.log</value><value name="rlimit_files">51200</value><value name="rlimit_core">0</value><value name="chroot"></value><value name="chdir"></value><value name="catch_workers_output">yes</value><value name="max_requests">500</value><value name="allowed_clients">127.0.0.1</value><value name="environment"><value name="HOSTNAME">$HOSTNAME</value><value name="PATH">/usr/local/bin:/usr/bin:/bin</value><value name="TMP">/tmp</value><value name="TMPDIR">/tmp</value><value name="TEMP">/tmp</value><value name="OSTYPE">$OSTYPE</value><value name="MACHTYPE">$MACHTYPE</value><value name="MALLOC_CHECK_">2</value></value></section></workers></configuration>
五、创建www用户组及www用户
/usr/sbin/groupadd www/usr/sbin/useradd -g www www
六、编译安装Nginx
tar zxvf nginx-0.6.35.tar.gzcd nginx-0.6.35/默认安装:./configuremake && make install默认情况下,Nginx 会被安装在 /usr/local/nginx。通过设定编译选项,你可以改变这个设定。
指定编译选项安装,如:./configure --user=www --group=www --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_modulemake && make installcd ../
七、创建fcgi.conf文件
rm -f /usr/local/webserver/nginx/conf/fcgi.confvi /usr/local/webserver/nginx/conf/fcgi.conf
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询