美文网首页
阿里云nginx配置:

阿里云nginx配置:

作者: 小小的小帅 | 来源:发表于2020-03-20 08:11 被阅读0次
    1. gcc 环境
    yum install gcc-c++
    
    1. 安装PCRE pcre-devel
      Nginx的Rewrite模块和HTTP核心模块会使用到PCRE正则表达式语法
    yum install -y pcre pcre-devel
    
    1. 安装zlib
      zlib库提供了开发人员的压缩算法
    yum install -y zlib zlib-devel
    
    1. 安装Open SSL
      nginx支持 https协议
     yum -y install openssl openssl-devel
    
    1. nginx编译
    ./configure --with-http_ssl_module  --prefix=/usr/local/nginx
    make  && make install
    
    1. nginx重启:
      /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf -s reload
      日志查看
      tail -f /usr/local/nginx/logs/access.log
    2. nginx配置
    user  root;
    #user  nobody;
    worker_processes  1;
    
    events {
        worker_connections  1024;
    }
    
    http {
        include       mime.types;
        default_type  application/octet-stream;
        #access_log  logs/access.log  main;
        sendfile        on;
        keepalive_timeout  65;
    
        server {
            listen 9092 ssl ;
            server_name  www.scydss.com;
            ssl_certificate      /usr/local/nginx/conf/ssl/www.scydss.com.pem;
            ssl_certificate_key  /usr/local/nginx/conf/ssl/www.scydss.com.key;
    
            ssl_session_timeout  5m;
            ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
            ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
            ssl_prefer_server_ciphers  on;
    
            location / {
               proxy_pass  http://129.211.24.177:9090;
            }
            location /image {
                root   /root/file/;
                index  index.html index.htm;
            }
        }
    
      
    }
    
    
    1. linux中将nginx配置成service
      安装完nginx后
     vim /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/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
    

    执行

    chkconfig --add /etc/init.d/nginx
    chmod 755 /etc/init.d/nginx
    chkconfig --add nginx
    

    如果想随系统启动就执行

    /sbin/chkconfig --level 345 nginx on
    

    nginx启动、停止、无间断服务重启,可选 start | stop | restart | reload | status | help

    service nginx start
    service nginx stop
    service nginx reload
    

    相关文章

      网友评论

          本文标题:阿里云nginx配置:

          本文链接:https://www.haomeiwen.com/subject/dtmryhtx.html