0
点赞
收藏
分享

微信扫一扫

Linux Nginx安装过程


Linux Nginx安装过程

 

安装nginx

wget http://nginx.org/download/nginx-1.9.3.tar.gz
tar -zxvf nginx-1.9.3.tar.gz
cd nginx-1.9.3
 
./configure --prefix=/usr/local/nginx \
--sbin-path=/usr/local/nginx/nginx \
--conf-path=/usr/local/nginx/nginx.conf \
--pid-path=/usr/local/nginx/nginx.pid \
--with-http_ssl_module \
--with-pcre=/lab/re/pcre-8.36 \
--with-zlib=/lab/re/zlib-1.2.8 \
--with-openssl=/lab/re/openssl-1.0.2d
 
#pcre zlib openssl源码目录,而不是编译安装后的目录。 
 
make
make install
 
apache也是使用的80端口,所以需要修改一下apache端口
sudo vi /usr/local/apache2/conf/httpd.conf
Listen 8099 #改成8099
apachectl restart
 
启动nginx
/usr/local/nginx/nginx
检查80端口
netstat -ano|grep 80
访问一下试试
curl 127.0.0.1
 
配置nginx 
vi /usr/local/nginx/nginx.conf
添加以下内容
server {
        listen   80;
        server_name svn.crabdave.org;
        location / {
#如果nginx的监听端口不是默认的80端口,改为其他端口 如8099端口。$host:8099
#如果不配置,则后端服务器中request.getServerPort()无法获得正确的端口,返回的仍然是80;
                proxy_set_header Host $host:8099;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-Proto https;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_pass http://127.0.0.1:8099;
                }
        }

 

注意:添加一些超时、缓存的配置(放在 location 配置段里)

       

client_max_body_size     100m;
            client_body_buffer_size  128k;
            proxy_connect_timeout    600;
            proxy_read_timeout       600;
            proxy_send_timeout       6000;
            proxy_buffer_size        32k;
            proxy_buffers            4 64k;
            proxy_busy_buffers_size 128k;
            proxy_temp_file_write_size 512k;

 

 测试一下配置文件

/data/re/nginx/nginx -t

 

重新加载配置

 /usr/local/nginx/nginx -s reload

 

修改hosts

设置svn.crabdave.org解析到你的nginx服务器ip

windows 运行drivers 修改hosts文件

192.168.1.104 www.crabdave.org

192.168.1.104 svn.crabdave.org

 

运行 cmd  

ipconfig /flushdns来刷新dns缓存

访问http://svn.crabdave.org

 

Linux

vi /etc/hosts

添加

127.0.0.1 www.crabdave.org

127.0.0.1 svn.crabdave.org

重启网卡

/etc/init.d/network restart

curl svn.crabdave.org

 

配置开机自启动

vi /etc/init.d/nginx  (输入下面的代码)

 

#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# 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: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/nginx
nginx_config=/usr/local/nginx/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 $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
 
:wq  保存并退出
 
设置权限
chmod a+x /etc/init.d/nginx   (a+x ==> all user can execute  所有用户可执行)
 
vi /etc/rc.local
加入一行  /etc/init.d/nginx start    保存并退出

举报

相关推荐

0 条评论