美文网首页
Linux下安装Nginx

Linux下安装Nginx

作者: beyond阿亮 | 来源:发表于2022-04-23 21:47 被阅读0次

    Linux下安装Nginx

    备注

        Nginx统一安装1.10.2版本
    
    

    1.安装编译工具及库文件

    yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel
    
    

    2.安装PCRE

    cd /data/software/
    wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
    tar zxvf pcre-8.35.tar.gz
    
    cd pcre-8.35
    ./configure
    make && make install
    
    pcre-config --version
    
    

    3.安装Nginx

    cd /data/software/
    wget -O /data/software/nginx-1.10.2.tar.gz http://nginx.org/download/nginx-1.10.2.tar.gz
    tar -zxvf /data/software/nginx-1.10.2.tar.gz
    cd /data/software/nginx-1.10.2
    
    ./configure --prefix=/data/apps/nginx-main \
        --pid-path=/data/logs/nginx-main/nginx.pid \
        --lock-path=/data/apps/nginx-main/nginx.lock \
        --error-log-path=/data/logs/nginx-main/error.log \
        --http-log-path=/data/logs/nginx-main/access.log \
        --http-client-body-temp-path=/data/temps/nginx-main/client_body_temp \
        --http-proxy-temp-path=/data/temps/nginx-main/proxy_temp \
        --http-fastcgi-temp-path=/data/temps/nginx-main/fastcgi_temp \
        --http-uwsgi-temp-path=/data/temps/nginx-main/uwsgi_temp \
        --http-scgi-temp-path=/data/temps/nginx-main/scgi_temp \
        --with-http_stub_status_module \
        --with-http_ssl_module \
        --with-http_realip_module \
        --with-pcre=/data/software/pcre-8.35
    
    make
    make install
    
    

    4.Nginx配置

    cd /data/apps/nginx-main/conf/
    vim nginx.conf
     
    
    user  root;
    worker_processes  2;
    
    #error_log  logs/error.log;
    #error_log  logs/error.log  notice;
    #error_log  logs/error.log  info;
    
    #pid        logs/nginx.pid;
    
    
    events {
        worker_connections  1024;
    }
    
    
    http {
        include       mime.types;
        default_type  application/octet-stream;
    
        #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
        #                  '$status $body_bytes_sent "$http_referer" '
        #                  '"$http_user_agent" "$http_x_forwarded_for"';
       
        log_format  main  '$remote_addr $host $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for" "$request_time" "$bytes_sent" "$body_bytes_sent"';
        access_log  /data/apps/nginx-main/access.log  main;
    
        #access_log  logs/access.log  main;
    
        sendfile        on;
        #tcp_nopush     on;
    
        #keepalive_timeout  0;
        keepalive_timeout  65;
    
        #gzip  on;
    
        client_max_body_size 100m;
        gzip  on;
    
        upstream manage_upstream {
            server 127.0.0.1:8080;
        }
    
    
        server {
            listen       8888;
            server_name  localhost;
    
            #charset koi8-r;
    
            #access_log  logs/host.access.log  main;
    
            location /manage {
                proxy_pass http://manage_upstream;
                proxy_set_header  Host                $host;
                proxy_set_header  X-Real-IP           $proxy_protocol_addr;
                proxy_set_header  X-Forwarded-For     $proxy_add_x_forwarded_for;
                proxy_set_header  X-Forwarded-Port    $server_port;  
            }
    
            location / {
                root   html;
                index  index.html index.htm;
            }
    
            #error_page  404              /404.html;
    
            # redirect server error pages to the static page /50x.html
            #
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
    
            # proxy the PHP scripts to Apache listening on 127.0.0.1:80
            #
            #location ~ \.php$ {
            #    proxy_pass   http://127.0.0.1;
            #}
    
            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
            #location ~ \.php$ {
            #    root           html;
            #    fastcgi_pass   127.0.0.1:9000;
            #    fastcgi_index  index.php;
            #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            #    include        fastcgi_params;
            #}
    
            # deny access to .htaccess files, if Apache's document root
            # concurs with nginx's one
            #
            #location ~ /\.ht {
            #    deny  all;
            #}
        }
    
    
        # another virtual host using mix of IP-, name-, and port-based configuration
        #
        #server {
        #    listen       8000;
        #    listen       somename:8080;
        #    server_name  somename  alias  another.alias;
    
        #    location / {
        #        root   html;
        #        index  index.html index.htm;
        #    }
        #}
    
    
        # HTTPS server
        #
        #server {
        #    listen       443 ssl;
        #    server_name  localhost;
    
        #    ssl_certificate      cert.pem;
        #    ssl_certificate_key  cert.key;
    
        #    ssl_session_cache    shared:SSL:1m;
        #    ssl_session_timeout  5m;
    
        #    ssl_ciphers  HIGH:!aNULL:!MD5;
        #    ssl_prefer_server_ciphers  on;
    
        #    location / {
        #        root   html;
        #        index  index.html index.htm;
        #    }
        #}
    
    }
     
    

    4. 启动Nginx

     /data/apps/nginx-main/sbin/nginx
     mkdir -pv /data/temps/nginx-main/client_body_temp
     /data/apps/nginx-main/sbin/nginx -s reload 重载配置
    

    相关文章

      网友评论

          本文标题:Linux下安装Nginx

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