nginx 컴 파일 설치 centos 7

nginx 컴 파일 설치

yum install -y vim lrzsz tree screen psmisc lsof tcpdump wget  ntpdate 
gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl  openssl-devel 
systemd-devel net-tools iotop bc  zip unzip zlib-devel bash-completion 
nfs-utils automake libxml2  libxml2-devel libxslt libxslt-devel perl
perl-ExtUtils-Embed

           :

         : https://nginx.org/download/
cd /usr/local/src/
                
wget https://nginx.org/download/nginx-1.12.2.tar.gz 
              ,                
tar xf nginx-1.12.2.tar.gz 
   
cd nginx-1.12.2/
     
 ./configure --prefix=/apps/nginx \--user=nginx  \--group=nginx \--with-http_ssl_module
 \--with-http_v2_module \--with-http_realip_module \--with-http_stub_status_module 
 \--with-http_gzip_static_module \--with-pcre \--with-stream \--with-stream_ssl_module
 \--with-stream_realip_module
          nginx     ,         
make
    
make install
    ,                  
useradd nginx -s /sbin/nologin -u 2000
     nginx        

chown nginx.nginx -R /apps/nginx/
      nginx                   nginx
  :nginx      ,        :
conf:  nginx       ,  nginx.conf nginx             ,   .conf       nginx      ,  fastcgi      fastcgi.conf fastcgi_params    ,                ,    .default  ,            default    。 
html:      nginx    web  ,             web  ,      50x web               。
logs:    nginx               ,logs          ,   /var/logs/nginx  。 
sbin:  nginx       ,                 。
 /apps/nginx/sbin/nginx  -V 
                    
vim /usr/lib/systemd/system/nginx.service 
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/apps/nginx/logs/nginx.pid
#Nginx will fail to start if /run/nginx.pid already exists but has the wrong
#SELinux context. This might happen when running `nginx -t` from the cmdline.
 https://bugzilla.redhat.com/show_bug.cgi?id=1268621
ExecStartPre=/usr/bin/rm -f /apps/nginx/logs/nginx.pid
ExecStartPre=/apps/nginx/sbin/nginx -t
ExecStart=/apps/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
#KillSignal=SIGQUIT
#TimeoutStopSec=5
KillMode=process
PrivateTmp=true

[Install]
WantedBy=multi-user.target
       nginx      
systemctl daemon-reload 
      unit   ,    unit  ,   systemd       ;
systemctl  start  nginx 
  nginx  
systemctl  enable  nginx 
      nginx  
 systemctl  status   nginx 
● nginx.service - The nginx HTTP and reverse proxy server 
  Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset:
 disabled)
   Active: active (running) since Mon 2019-02-18 11:11:38 CST; 10s ago 
 Main PID: 6348 (nginx) 
   CGroup: /system.slice/nginx.service 
           ├─6348 nginx: master process /apps/nginx/sbin/nginx
   nginx       active(running)  running         

 Welcome to nginx!
 If you see this page, the nginx web server is successfully installed and 
 working. Further configuration is required.

 For online documentation and support please refer to nginx.org.
 Commercial support is available at nginx.com.

 Thank you for using nginx
         IP   nginx  web  !

설정 테스트: pc 웹 사이트 새로 만 들 기
      nginx         keepalive_timeout  65;
      include /apps/nginx/conf/conf.d/*.conf; 
    conf/conf.d/    .conf         ,       !
             conf.d          ;mkdir  /apps/nginx/conf/conf.d
vim /apps/nginx/conf/conf.d/pc.conf 
 server {
  listen 80;
  server_name www.lvyao.com;
  location / {
    root /data/nginx/html/pc;
  }
}
     pc web     
 mkdir /data/nginx/html/pc -p

       web    
 echo "pc web" > /data/nginx/html/pc/index.html 
           html   
 windows C:\Windows\System32\drivers\etc
 hosts     DNS    
  IP                        
172.22.143.132     www.lvyao.com
 systemctl reload nginx 
                 

모 바 일 웹 사이트 새로 만 들 기:
vim /apps/nginx/conf/conf.d/mobile.confserver {
  listen 80;
  server_name mobile.lvyao.net;
  location / {
    root /data/nginx/html/mobile;
  }
}
    mobile web     
mkdir /data/nginx/html/mobile  -p
      web    
echo "mobile web" >> /data/nginx/html/mobile/index.html
          html   
 windows C:\Windows\System32\drivers\etc
hosts     DNS    
  IP                       
172.22.143.132    mobile.lvyao.net
systemctl reload nginx 
                 

루트 와 alias
  web    ,   location   ,          root+location, 

server {
  listen 80;
  server_name www.lvyao.com;
  location / {
    root /data/nginx/html/pc;
  }

  location /about {
    root /data/nginx/html/pc;
    index index.html;
  }
}
  wep        
mkdir  /data/nginx/html/pc/about
        about  

echo about > /data/nginx/html/pc/about/index.html
  wep           html   

   Nginx     
alias:      ,                  , :

vim /apps/nginx/conf/conf.d/alias.conf
server {
  listen 80;
  server_name www.lvyao.com;
  location / {
    root /data/nginx/html/pc;
  }

  location /about {  #  alias   uri                     ,  403
    alias /data/nginx/html/pc; #   about   ,   alias   /data/nginx/html/pc
         。 
    index index.html;
  }
}
  alias     
    Nginx     

좋은 웹페이지 즐겨찾기