admin 发表于 2022-1-6 15:05:47

NGINX安装


1、安装依赖
yum -y install openssl openssl-devel;
yum -y install pcre-devel;
yum -y install libxml2 libxml2-dev;
yum -y install libxslt-devel;
yum install gd gd-devel;2、 下载Nginx源码包curl -L https://nginx.org/download/nginx-1.18.0.tar.gz-o/opt/;

wget url -P https://nginx.org/download/nginx-1.18.0.tar.gz -O /opt/;

3、编译

cd /opt/nginx-1.18.0;
./configure --prefix=/usr/local/nginx --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_gzip_static_module --http-client-body-temp-path=/var/temp/nginx/client --http-proxy-temp-path=/var/temp/nginx/proxy --http-fastcgi-temp-path=/var/temp/nginx/fastcgi --http-uwsgi-temp-path=/var/temp/nginx/uwsgi --http-scgi-temp-path=/var/temp/nginx/scgi --with-http_stub_status_module --with-http_ssl_module --with-file-aio --with-http_realip_module--with-http_v2_module;4、nginx高级用法
#usernobody;
worker_processes1;

#error_loglogs/error.log;
#error_loglogs/error.lognotice;
#error_loglogs/error.loginfo;

pid      /run/nginx.pid;


events {
    worker_connections1024;
}


stream {
   log_format proxy         '$remote_addr [$time_local] '
                       '$protocol $status $bytes_sent $bytes_received '
                       '$session_time "$upstream_addr" '
                       '"$upstream_bytes_sent" "$upstream_bytes_received" "$upstream_connect_time"';

    access_log /var/log/nginx/tcp-access.log proxy ;
    open_log_file_cache off;

    map $remote_addr $stream_service {
<font color="#ff0000">        "180.166.3.163" aaa_server;
        default http_server;</font>
    }

    upstream aaa_server {
        server 127.0.0.1:8443;       
    }

    upstream http_server {
        server 127.0.0.1:6443;
    }

   server {
      listen 443 reuseport;
      listen [::]:443 reuseport;
      proxy_pass        $stream_service;
      ssl_preread on; #开启 ssl_preread
    }
}



http {
    include       mime.types;
    default_typeapplication/octet-stream;

    #log_formatmain'$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_loglogs/access.logmain;

    sendfile      on;
    #tcp_nopush   on;

    #keepalive_timeout0;
    keepalive_timeout65;

    #gzipon;
    server {
      listen       80 ;
      listen       [::]:80 ;
      server_name<font color="#ff0000">aaa</font>;
      root         /usr/share/nginx/html;
       
        if ($scheme = http ) {
           return 301 https://$host$request_uri;
        }
    }


    server {
            listen              6443 ssl http2;
        listen       [::]:6443 ssl http2;
            server_name <font color="#ff0000">aaa</font>;
        root         /usr/share/nginx/html;

        ssl_certificate "/etc/nginx/ssl/fullchain.crt";
        ssl_certificate_key "/etc/nginx/ssl/<font color="#ff00ff">aaa</font>.key";
        ssl_session_cache shared:SSL:1m;
        ssl_session_timeout10m;
        ssl_prefer_server_ciphers on;

        location / {
       
          proxy_set_header X-Real-IP $remote_addr;
                 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            #设定需要反代的域名,可以加端口号
          proxy_pass <font color="#ff0000">http://www.163.com/</font>;
            #替换网站内容
            sub_filter '<span style="color: rgb(255, 0, 0);">www.163.com</span>' '<font color="#ff0000">aaa</font>';
        }

        error_page   500 502 503 504/50x.html;
        location = /50x.html {
          root   html;
        }
    }

}


页: [1]
查看完整版本: NGINX安装