• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

nginx (待续)

mysql 搞代码 4年前 (2022-01-09) 42次浏览 已收录 0个评论

关于相关的支持程序,也可以从在这里下载并编译安装 openssl http://www.openssl.org/source/ pcre http://www.pcre.org nginx 的 rewrite 网站页面地址重写功能需要正则表达式模块 PCRE,另外页面压缩传输需要 zlib 为在配置文件中使用正则表达式,需要安装


关于相关的支持程序,也可以从在这里下载并编译安装

openssl

http://www.openssl.org/source/


pcre

http://www.pcre.org


nginx 的 rewrite 网站页面地址重写功能需要正则表达式模块 PCRE,另外页面压缩传输需要 zlib

为在配置文件中使用正则表达式,需要安装pcre和pcre-devel,

注:nginx-0.6.32已经不存在已经安装了pcre及pcre-deve 的rpm包却找不到pcre的问题。

注: 根据 October 2006 message 的消息,md5 在一个现在不再使用的 http 缓存模块中用到,而 sha1 用在一个未完成的 mysql 库模块,所以它们当前都不是必须的


建议仔细阅读wiki上的module说明

http://wiki.codemongers.com/Main


./configure –prefix=/usr/local/nginx  \

–with-openssl=/usr/include \

–with-http_stub_status_module  \

–without-poll_module \

–without-select_module

make

make install




#运行用户

user  nobody nobody;


#启动进程

worker_processes  2;


#全局错误日志及PID文件

error_log  logs/error.log notice;

pid        logs/nginx.pid;


#工作模式及连接数上限

events {

        use epoll;

        worker_connections      1024;

}


#设定http服务器,利用它的反向代理功能提供负载均衡支持

http {

        #设定mime类型

        include       mime.types;

        default_type  application/octet-stream;


        #设定日志格式

        log_format main         ‘$remote_addr – $remote_user [$time_local] ‘

                                                '”$request” $status $bytes_sent ‘

                                                '”$http_referer” “$http_user_agent” ‘

                                                '”$gzip_ratio”‘;


        log_format download ‘$remote_addr – $remote_user [$time_local] ‘

                                     来&源gao@dai!ma.com搞$代^码%网           '”$request” $status $bytes_sent ‘

                                                '”$http_referer” “$http_user_agent” ‘

                                                '”$http_range” “$sent_http_content_range”‘;


        #设定请求缓冲

        client_header_buffer_size    1k;

        large_client_header_buffers  4 4k;


        #开启gzip模块

        gzip on;

        gzip_min_length  1100;

        gzip_buffers     4 8k;

        gzip_types       text/plain;


        output_buffers   1 32k;

        postpone_output  1460;


        #设定access log

        access_log  logs/access.log  main;


        client_header_timeout  3m;

        client_body_timeout    3m;

        send_timeout           3m;


        sendfile                on;

        tcp_nopush              on;

        tcp_nodelay             on;


        keepalive_timeout  65;


        #设定负载均衡的服务器列表

        upstream backend {

                #weigth参数表示权值,权值越高被分配到的几率越大

                #本机上的Squid开启3128端口

                #server 192.168.8.1:3128 weight=5;

                server 192.168.8.2:80   weight=6;

                server 192.168.8.3:80   weight=6;

        }


        #设定虚拟主机

        server {

                listen          80;

                server_name     192.168.7.192 http://www.test.com;


                charset gb2312;


                #设定本虚拟主机的访问日志

                access_log  logs/www.test.access.log  main;


                #如果访问 /img/*, /js/*, /css/* 资源,则直接取本地文件,不通过squid

                #如果这些文件较多,不推荐这种方式,因为通过squid的缓存效果更好

                #location ~ ^/(img|js|css)/  {

                #        root    /data3/Html;

                #        expires 24h;

                #}


                #对 “/” 启用负载均衡

                location / {

                        proxy_pass      http://backend;


                        proxy_redirect          off;

                        #proxy_set_header        Host $host;

                        #proxy_set_header        X-Real-IP $remote_addr;

                        #proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;

                        client_max_body_size    10m;

                        client_body_buffer_size 128k;

                        proxy_connect_timeout   90;

                        proxy_send_timeout      90;

                        proxy_read_timeout      90;

                        proxy_buffer_size       4k;

                        proxy_buffers           4 32k;

                        proxy_busy_buffers_size 64k;

                        proxy_temp_file_write_size 64k;

                }


                #设定查看Nginx状态的地址

                location /NginxStatus {

                        stub_status             on;

                        access_log              on;

                        #auth_basic              ”NginxStatus”;

                        #auth_basic_user_file  conf/htpasswd;

                }

        }

}










curl -I http://127.0.0.1 查看http头


nginx启动脚本,放于/etc/init.d/nginxd

#!/bin/bash

# nginx Startup script for the Nginx HTTP Server

# this script create it by jackbillow at 2007.10.15.

# it is v.0.0.2 version.

# if you find any errors on this scripts,please contact jackbillow.

# and send mail to jackbillow at gmail dot com.

#

# chkconfig: – 85 15

# description: Nginx is a high-performance web and proxy server.

#              It has a lot of features, but it’s not for everyone.

# processname: nginx

# pidfile: /usr/local/nginx/logs/nginx.pid

# config: /usr/local/nginx/conf/nginx.conf

nginxd=/usr/local/nginx/sbin/nginx

nginx_config=/usr/local/nginx/conf/nginx.conf

nginx_pid=/var/run/nginx.pid

RETVAL=0

prog=”nginx”

# Source function library.

. /etc/rc.d/init.d/functions

# Source networking configuration.

. /etc/sysconfig/network

# Check that networking is up.

[ ${NETWORKING} = “no” ] && exit 0

[ -x $nginxd ] || exit 0

# Start nginx daemons functions.

start() {

if [ -e $nginx_pid ];then

   echo “nginx already running….”

   exit 1

fi

   echo -n $”Starting $prog: “

   daemon $nginxd -c ${nginx_config}

   RETVAL=$?

   echo

   [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx

   return $RETVAL

}

# Stop nginx daemons functions.

stop() {

        echo -n $”Stopping $prog: “

        killproc $nginxd

        RETVAL=$?

        echo

        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid

}

# reload nginx service functions.

reload() {

    echo -n $”Reloading $prog: “

    #kill -HUP `cat ${nginx_pid}`

    killproc $nginxd -HUP

    RETVAL=$?

    echo

}

# See how we were called.

case “$1” in

start)

        start

        ;;

stop)

        stop

        ;;

reload)

        reload

        ;;

restart)

        stop

        start

        ;;

status)

        status $prog

        RETVAL=$?

        ;;

*)

        echo $”Usage: $prog {start|stop|restart|reload|status|help}”

        exit 1

esac

exit $RETVAL


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:nginx (待续)

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址