1、按照官方提供的脚本挂载脚本,增加swap分区。
2、下载nginx,解压缩,配置nginx
./configure --prefix=/home/web/nginx --conf-path=/home/web/nginx/conf/nginx.conf --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --with-file-aio --with-pcre
报错,没有C编译环境,安装之
yum -y install gcc
yum install -y gcc gcc-c++
yum install -y install make gcc
再来
./configure...
报错,./configure: error: the HTTP rewrite module requires the PCRE library.
好吧,下载 wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.32.tar.gz
tar -zxvf pcre-8.32.tar.gz
cd pcre-8.32
./configure
make
make install
再来,报错./configure: error: SSL modules require the OpenSSL library.
没说的,yum -y install openssl openssl-devel
再来
./configure...
make
make install
groupadd nginx
useradd -g nginx nginx
mkdir /home/web/nginx/conf/webs
vi /home/web/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 {
use epoll;
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"';#access_log logs/access.log main;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;client_max_body_size 50m;
large_client_header_buffers 4 128k;
client_header_buffer_size 128k;
server_names_hash_bucket_size 128;fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;gzip_static on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_disable "MSIE [1-6]\.";
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;aio on;
directio 1;
output_buffers 1 128k;include webs/*.conf;
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;# location / {
# root html;
# index index.html index.htm;
# }
#}}
配置通用的php-cgi加载脚本
vi /home/web/nginx/conf/fcgi.conf
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
保存文档。
建立一个虚拟主机配置文件
vi /home/web/nginx/conf/webs/defaults.conf
输入如下内容
server {
listen 80;
server_name XXX.COM;#charset koi8-r;
#access_log logs/host.access.log main;
root /home/www/xxx.com;
index index.html index.htm index.php default.php;
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
..........
配置nginx启动
vi /etc/init.d/nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
#
# chkconfig: 234 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /home/web/nginx/conf/nginx.conf
# pidfile: /home/web/nginx/logs/nginx.pid# Source function library.
. /etc/rc.d/init.d/functions# Source networking configuration.
. /etc/sysconfig/network# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0nginx="/home/web/nginx/sbin/nginx"
prog=$(basename $nginx)NGINX_CONF_FILE="/home/web/nginx/conf/nginx.conf"
lockfile=/var/lock/subsys/nginx
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}restart() {
configtest || return $?
stop
start
}reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}force_reload() {
restart
}configtest() {
$nginx -t -c $NGINX_CONF_FILE
}rh_status() {
status $prog
}rh_status_q() {
rh_status >/dev/null 2>&1
}case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
chmod +x /etc/init.d/nginx
/sbin/chkconfig nginx on
/sbin/chkconfig --list nginx
nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off
完成之后,就可以使用以下命令了
service nginx start
service nginx stop
service nginx restart
service nginx reload
/etc/init.d/nginx start
/etc/init.d/nginx stop
/etc/init.d/nginx restart
/etc/init.d/nginx reload
很遗憾,启动报错,
Starting nginx: /home/web/nginx/sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory
> ldd $(which /home/web/nginx/sbin/nginx)
linux-vdso.so.1 => (0x00007fff3291f000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003b99600000)
libcrypt.so.1 => /lib64/libcrypt.so.1 (0x0000003ba5a00000)
libpcre.so.1 => not found
libssl.so.10 => /usr/lib64/libssl.so.10 (0x00007f1a5d4fc000)
libcrypto.so.10 => /usr/lib64/libcrypto.so.10 (0x00007f1a5d162000)
libdl.so.2 => /lib64/libdl.so.2 (0x0000003b99200000)
libz.so.1 => /lib64/libz.so.1 (0x00007f1a5cf4b000)
libc.so.6 => /lib64/libc.so.6 (0x0000003b98e00000)
/lib64/ld-linux-x86-64.so.2 (0x0000003b98a00000)
libfreebl3.so => /lib64/libfreebl3.so (0x0000003ba6600000)
libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007f1a5cd06000)
libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007f1a5ca20000)
libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007f1a5c81b000)
libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007f1a5c5ef000)
libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007f1a5c3e4000)
libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007f1a5c1e0000)
libresolv.so.2 => /lib64/libresolv.so.2 (0x0000003b9b200000)
libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f1a5bfc0000)
缺少文件,那就简单了,find 然后ln
ln -s /usr/local/lib/libpcre.so.1 /lib64/libpcre.so.1
至此,启动nginx 成功