Nginx
和编译PHP一样非常简单:
- cd ..
- sudo wget http://sysoev.ru/nginx/nginx-0.6.35.tar.gz
- sudo tar zxvf nginx-0.6.35.tar.gz
- sudo rm -f nginx-0.6.35.tar.gz
- cd nginx-0.6.35
- sudo ./configure --sbin-path=/usr/local/sbin --with-http_ssl_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-http_stub_status_module
- sudo make && sudo make install
再创建一个链接:
- sudo ln -s /usr/local/nginx/conf /etc/nginx
-
下一步是可有可无的,但我一直使用至今,说说也无妨。打开/etc/nginx/nginx.conf,最终修改结果如下:
- user www-data;
- worker_processes 6;
-
- events {
- worker_connections 1024;
- }
-
- http {
- include mime.types;
- default_type application/octet-stream;
- sendfile on;
- keepalive_timeout 10 10;
-
- gzip on;
- gzip_comp_level 1;
- gzip_proxied any;
- gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
-
- 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 /var/log/nginx_access.log main;
-
- error_log /var/log/nginx_error.log debug;
-
- include /usr/local/nginx/sites-enabled/*;
- }
我们也设置了一些FastCGI参数,让PHP不会噎着,也可以避免Nginx 503错误,打开/etc/nginx/fastcgi_params,添加以下参数:
- fastcgi_connect_timeout 60;
- fastcgi_send_timeout 180;
- fastcgi_read_timeout 180;
- fastcgi_buffer_size 128k;
- fastcgi_buffers 4 256k;
- fastcgi_busy_buffers_size 256k;
- fastcgi_temp_file_write_size 256k;
- fastcgi_intercept_errors on;
最后,我们创建一个SystemV风格的启动脚本,保存为/etc/init.d/nginx。
- #! /bin/sh
- ### BEGIN INIT INFO
- # Provides: nginx
- # Required-Start: $all
- # Required-Stop: $all
- # Default-Start: 2 3 4 5
- # Default-Stop: 0 1 6
- # Short-Description: starts the nginx web server
- # Description: starts nginx using start-stop-daemon
- ### END INIT INFO
-
- PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
- DAEMON=/usr/local/sbin/nginx
- NAME=nginx
- DESC=nginx
-
- test -x $DAEMON || exit 0
-
- # Include nginx defaults if available
- if [ -f /etc/default/nginx ] ; then
- . /etc/default/nginx
- fi
-
- set -e
-
- case "$1" in
- start)
- echo -n "Starting $DESC: "
- start-stop-daemon --start --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
- --exec $DAEMON -- $DAEMON_OPTS
- echo "$NAME."
- ;;
- stop)
- echo -n "Stopping $DESC: "
- start-stop-daemon --stop --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
- --exec $DAEMON
- echo "$NAME."
- ;;
- restart|force-reload)
- echo -n "Restarting $DESC: "
- start-stop-daemon --stop --quiet --pidfile \
- /usr/local/nginx/logs/$NAME.pid --exec $DAEMON
- sleep 1
- start-stop-daemon --start --quiet --pidfile \
- /usr/local/nginx/logs/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS
- echo "$NAME."
- ;;
- reload)
- echo -n "Reloading $DESC configuration: "
- start-stop-daemon --stop --signal HUP --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
- --exec $DAEMON
- echo "$NAME."
- ;;
- *)
- N=/etc/init.d/$NAME
- echo "Usage: $N {start|stop|restart|force-reload}" >&2
- exit 1
- ;;
- esac
-
- exit 0
不要忘了设置可执行权限。
(责任编辑:admin) |