9isuper论坛

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 3229|回复: 0

NGINX安装

[复制链接]

10

主题

11

帖子

101

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
101
发表于 2022-1-6 15:05:47 | 显示全部楼层 |阅读模式

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

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

复制代码
3、编译

  1. cd /opt/nginx-1.18.0;
  2. ./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高级用法
  1. #user  nobody;
  2. worker_processes  1;

  3. #error_log  logs/error.log;
  4. #error_log  logs/error.log  notice;
  5. #error_log  logs/error.log  info;

  6. pid        /run/nginx.pid;


  7. events {
  8.     worker_connections  1024;
  9. }


  10. stream {
  11.      log_format proxy         '$remote_addr [$time_local] '
  12.                          '$protocol $status $bytes_sent $bytes_received '
  13.                          '$session_time "$upstream_addr" '
  14.                          '"$upstream_bytes_sent" "$upstream_bytes_received" "$upstream_connect_time"';

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

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

  21.     upstream aaa_server {
  22.         server 127.0.0.1:8443;       
  23.     }

  24.     upstream http_server {
  25.         server 127.0.0.1:6443;
  26.     }

  27.      server {
  28.         listen 443 reuseport;
  29.         listen [::]:443 reuseport;
  30.         proxy_pass        $stream_service;
  31.         ssl_preread on; #开启 ssl_preread
  32.     }
  33. }



  34. http {
  35.     include       mime.types;
  36.     default_type  application/octet-stream;

  37.     #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
  38.     #                  '$status $body_bytes_sent "$http_referer" '
  39.     #                  '"$http_user_agent" "$http_x_forwarded_for"';

  40.     #access_log  logs/access.log  main;

  41.     sendfile        on;
  42.     #tcp_nopush     on;

  43.     #keepalive_timeout  0;
  44.     keepalive_timeout  65;

  45.     #gzip  on;
  46.     server {
  47.         listen       80 ;
  48.         listen       [::]:80 ;
  49.         server_name  <font color="#ff0000">aaa</font>;
  50.         root         /usr/share/nginx/html;
  51.        
  52.         if ($scheme = http ) {
  53.            return 301 https://$host$request_uri;
  54.         }
  55.     }


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

  61.         ssl_certificate "/etc/nginx/ssl/fullchain.crt";
  62.         ssl_certificate_key "/etc/nginx/ssl/<font color="#ff00ff">aaa</font>.key";
  63.         ssl_session_cache shared:SSL:1m;
  64.         ssl_session_timeout  10m;
  65.         ssl_prefer_server_ciphers on;

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

  75.         error_page   500 502 503 504  /50x.html;
  76.         location = /50x.html {
  77.             root   html;
  78.         }
  79.     }

  80. }
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|9isuper ( 鄂ICP备15002592号 )

GMT+8, 2024-4-19 15:54 , Processed in 0.080899 second(s), 17 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表