nginx 소스 코드 설치 - centos 7

7734 단어
설치 플랫폼: centos 7.3
1. 지정 한 디 렉 터 리 에 가방 다운로드
wget http://nginx.org/download/nginx-1.16.1.tar.gz -P /tmp

2. 압축 해제 팩
tar -zxvf /tmp/nginx-1.16.1.tar.gz -C /tmp

3. 의존 팩 설치
yum -y install gcc
yum -y install zlib-devel
yum -y install pcre-devel
yum -y install openssl-devel

4. nginx 설정 컴 파일 설치
cd /tmp/nginx-1.16.1
./configure
make
make install

5. 기본 경로 로 시작
cd /usr/local/nginx/sbin
./nginx

6. 웹 페이지 방문 ip (selinux, iptables 를 먼저 닫 을 수 없습니다)
setenforce 0  #    selinux
systemctl stop firewalld 

7. 포트 변경
cd /usr/local/nginx/conf
 vi nginx.conf

8. 시동 설정, 두 가지 방법 중 하 나 를 취하 면 됩 니 다.
방법 1: echo '/ usr / local / nginx / sbin / nginx' > / etc / rc. localchmod u + x / etc / rc. local 방법 2: [root@localhost# cat < EOF > / lib / system / system / ngix. service \ # Nginx 서비스 시스템 시작 파일 만 들 기 [Unit] 설명 = nginxAfter = network. target
[Service]Type=forkingExecStart=/usr/local/nginx/sbin/nginxExecReload=/usr/local/nginx/sbin/nginx -s reloadExecStop=/usr/local/nginx/sbin/nginx -s quitPrivateTmp=true
[Install]WantedBy=multi-user.targetEOF
systemctl daemon-reload && systemctl start nginx && \systemctl enable nginx && systemctl status nginx
9. nginx 는 간단 한 부하 균형 을 설정 합 니 다.
cat </usr/local/nginx/conf/nginx.conf
worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { proxy_pass http://192.168.1.10:8080; proxy_pass http://192.168.1.10:8081; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
EOF

다음은 상용 설정 을 소개 합 니 다.
 10. 정상 대리
//              80             192.168.10.10   80    
upstream www.wukc.com{                          //        ,         
        server 192.168.10.10:80;            //           ip     
    }   
server{
listen  80;                                  //   80         
location  /{
         proxy_pass http://www.wukc.com;
         index  index.html index.php;
         }   
}

 11. 서로 다른 포트 에 따라 전송 
//         80            192.168.10.10 80  ,       8080         192.168.10.20 8080  
upstream www.wukc.com{
        server 192.168.10.10:80;
 }
 
upstream www.wukc2.com{
        server 192.168.10.20:8080;
 }
 
server{
listen 80;
location /{
    proxy_pass http://www.wukc.com;
    index  index.html index.php;
         }
}
 
server{
listen 8080;
location /{
    proxy_pass http://www.wukc2.com;
    index  index.html index.jsp;
        }
}

12. 네 가지 부하 균형
1:  :                      ,       down ,     
upstream www.wukc.com{
        server 192.168.10.10:80;
        server 192.168.10.20:80;
    }
server{
listen 80;
location /{
  proxy_pass http://www.wukc.com;
  index  index.html index.php index.jsp;
  }
}
 
2:ip_hash:       ip hash    ,                 ,    session   。
upstream www.wukc.com{
        ip_hash;
        server 192.168.10.10:80;
        server 192.168.10.20:80;
    }
server{
listen 80;
location /{
  proxy_pass http://www.wukc.com;
  index  index.html index.php index.jsp;
  }
}
 
3:weight:      ,weight        ,              。
upstream www.wukc.com{
        server 192.168.10.10:80 weight=10;
        server 192.168.10.20:80 weight=20;
    }
server{
listen 80;
location /{
  proxy_pass http://www.wukc.com;
  index  index.html index.php index.jsp;
  }
}
 
4: fair :                 ,           
upstream www.wukc.com{
        server 192.168.10.10:80 weight=10;
        server 192.168.10.20:80 weight=20;
        fair;
    }
server{
listen 80;
location /{
  proxy_pass http://www.wukc.com;
  index  index.html index.php index.jsp;
  }
}

13. 로 컬 퍼 가기 에이전트 (서로 다른 접미사 기반)
server {
    listen       80;
    server_name  localhost;
    location / {
        root   /usr/share/nginx/html;
        index  index.php index.html index.htm;
    }
   
    location ~ \.php$ {              //         .php    ,         800  
        proxy_pass   http://127.0.0.1:800;
    }
    location ~ \.jsp$ {            //         .jsp    ,         8080  
        proxy_pass   http://127.0.0.1:8080;
    }
    location ~ \.(jpg|png)$ {     //         .jpg .png     ,    /img    
       root  /img;
    }
}

 14. 서로 다른 방문 경로 가 서로 다른 서비스 설정 으로 전송
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
#    upstream,       
upstream kubesphere{
   server 172.21.210.10:30880;
}
upstream harbor{
   server 172.21.210.20:80;
}

    server {
        listen       443;
        server_name  localhost;
        location /kubesphere {              #       upstream   
            proxy_pass http://kubesphere;   #      upstream  ,      upstream
        }
       
        location /harbor {
            proxy_pass http://harbor;
        }

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

}

좋은 웹페이지 즐겨찾기