zoukankan      html  css  js  c++  java
  • linux中安装nginx

    安装nginx
    首先需要安装pcre库
    2.解压  tar -zxvf pcre-8.40.tar.gz
    3.进入安装包目录 cd pcre-8.40
    4.编译安装./configure
    make && make install
    5.查看PCRE版本pcre-config --version
    安装nginx
    2.解压  tar -zxvf nginx-1.14.0.tar.gz
    3.切换到安装目录cd nginx-1.14.0
    4../configure --prefix=/root/data/nginx1 后面跟的路径是它的安装路径
    5.echo $?
    6.make && make install
    7.echo $?
    8.cd /root/data/nginx1/
    9.ls  # 安装完成
    conf  html  logs  sbin
    创建nginx的主配置文件,因为我们不使用nginx自带的配置文件:
    1.mv nginx.conf nginx.conf.bak  ##对配置文件进行备份
    2.vim nginx.conf  # 内容如下
    user nobody nobody;
    worker_processes 2;
    error_log /root/data/nginx1/logs/nginx_error.log crit;
    pid /root/data/nginx1/logs/nginx.pid;
    worker_rlimit_nofile 51200;
    events
    {
        use epoll;
        worker_connections 6000;
    }
    http
    {
        include mime.types;
        default_type application/octet-stream;
        server_names_hash_bucket_size 3526;
        server_names_hash_max_size 4096;
        log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
        ' $host "$request_uri" $status'
        ' "$http_referer" "$http_user_agent"';
        sendfile on;
        tcp_nopush on;
        keepalive_timeout 30;
        client_header_timeout 3m;
        client_body_timeout 3m;
        send_timeout 3m;
        connection_pool_size 256;
        client_header_buffer_size 1k;
        large_client_header_buffers 8 4k;
        request_pool_size 4k;
        output_buffers 4 32k;
        postpone_output 1460;
        client_max_body_size 10m;
        client_body_buffer_size 256k;
        client_body_temp_path /root/data/nginx1/client_body_temp;
        proxy_temp_path /root/data/nginx1/proxy_temp;
        fastcgi_temp_path /root/data/nginx1/fastcgi_temp;
        fastcgi_intercept_errors on;
        tcp_nodelay on;
        gzip on;
        gzip_min_length 1k;
        gzip_buffers 4 8k;
        gzip_comp_level 5;
        gzip_http_version 1.1;
        gzip_types text/plain application/x-javascript text/css text/htm
        application/xml;
        add_header Access-Control-Allow-Origin *;
        include vhost/*.conf;
    }
    3.mkdir vhost  # 创建虚拟主机配置文件的存放目录
    4.cd vhost
    5.vim www.xxx.com.conf  # 创建虚拟主机配置文件,内容如下:
    upstream 192.168.204.134{
            # 需要负载的server列表,可以直接使用ip
            server 192.168.204.134:9999 weight=1;
            server 192.168.204.134:9080 weight=3;
            # server www.xxx.com:8080 weight=1;
            # server www.xxx.com:9080 weight=3;
    }
     
    server{
      listen 80;
      autoindex on;
      server_name 192.168.204;
      access_log /root/data/nginx1/logs/access.log combined;
      index index.html index.htm index.jsp;
     
      location / {
            proxy_pass http://192.168.204.134;
            add_header Access-Control-Allow-Origin *;
      }
    }
    3.检查nginx配置文件,显示没问题则启动nginx服务:
    1.cd /root/data/nginx1/sbin
    2. ./nginx -t  # 检查nginx配置文件
    nginx: the configuration file /root/data/nginx/conf/nginx.conf syntax is ok
    nginx: configuration file /root/data/nginx/conf/nginx.conf test is successful
    3../nginx -c /root/data/nginx1/conf/nginx.conf  # 启动nginx服务
    4.netstat -lntp | grep nginx  # 检查端口是否已监听
    5.ps aux |grep nginx  # 检查nginx进程是否正常
  • 相关阅读:
    寒假周总结一
    1657. Determine if Two Strings Are Close
    1656. Design an Ordered Stream
    695. Max Area of Island (BFS)
    695. Max Area of Island (DFS)
    Daily Coding Problem: Problem #713
    939. Minimum Area Rectangle
    259. 3Sum Smaller
    29. Divide Two Integers
    16. 3Sum Closest
  • 原文地址:https://www.cnblogs.com/Eleven-Alice/p/11017834.html
Copyright © 2011-2022 走看看