Nginx學習筆記(一)

Nginx學習筆記(一)

一、Nginx的特點與作用

     Nginx可以更快地響應請求。

     Web和反向代理服務器

     支持非常多的服務器軟件特性

     處理靜態資源

     用作反向代理

     用作負載均衡

二、Nginx編譯安裝    

 2.1 準備工作

  操作系統:CentOS7.3 IP地址:10.0.0.110

yum install -y gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel

 2.2 添加用戶

useradd -r nginx

 2.3 編譯安裝  

    ./configure --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_dav_module --with-http_stub_status_module --with-threads --with-file-aio

     make && make install

三、簡單web站點配置

 3.1設置環境變量  

  vi /etc/profile.d/nginx.sh #在最後一行加入下面字段

  export PATH="$PATH:/usr/local/nginx/sbin/"

 3.2啓動nginx

  nginx

 3.3配置nginx的web站點

  說明:站點A:www.huwho.cn URL映射的根目錄:/nginx/web  

     站點B:blog.huwho.cn URL映射的根目錄:/nginx/blog

  編譯配置文件

   vi /etc/nginx.conf   

   站點A配置段如下:

server {
        listen       80;
        server_name  www.huwho.cn;
            root /nginx/web;
            index index.html;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location /images/ {
            root   /nginx/;
        }
        #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;
        }

    站點B配置段如下:

 server {
        listen 80;
        server_name blog.huwho.cn;
        root /nginx/blog;
        index index.html;
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
      }
}

 3.4測試nginx語法

[root@pxe31 nginx]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

 3.5重載nginx

[root@pxe31 nginx]# nginx -s reload

 3.6站點目錄以及文件配置

  mkdir /nginx/{web,blog}

  echo www.huwho.cn > /nginx/web/index.html  

  echo blog.huwho.cn > /nginx/blog/index.html  

 3.7修改windows的hosts文件

wKiom1lGFPCzYHH9AABxV8ZXkG0344.png

 3.8訪問測試

  wKioL1lGFe6DNu8FAABMWMW8OCE068.png

wKiom1lGFgHjA9IpAABMNtzc9cM449.png


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章