Nginx之基本配置

來源:互聯網
上載者:User

標籤:nginx web

Nginx

1. 高效能的HTTP Server,支援高達20000並發訪問
2. 反向 Proxy伺服器,給網站加速
3. 做為前端一個負載平衡器
========================================================

一、準備工作
# service httpd stop
# chkconfig httpd off
所需的軟體: 開發庫,openssl-devel

二、部署Nginx
1. pcre: 支援Regex,地址修正rewrite
# tar zxf pcre-8.31.tar.gz
# cd pcre-8.31
# ./configure && make && make install
# ldconfig

2. nginx
# useradd www
# tar xvf nginx-1.2.2.tar.gz
# cd nginx-1.2.2
[[email protected] nginx-1.2.2]# ./configure \
> --user=www \
> --group=www \
> --prefix=/usr/local/nginx-1.2.2 \
> --with-http_stub_status_module \
> --with-http_sub_module \
> --with-http_ssl_module \
> --with-pcre=/usr/src/pcre-8.31       #pcre來源程式目錄

#--with-pcre=/usr/src/pcre-8.31 指的是pcre-8.31 的源碼路徑。
#--with-zlib=/usr/src/zlib-1.2.7 指的是zlib-1.2.7 的源碼路徑。

# make && make install
# ln -s /usr/local/nginx-1.2.2/ /usr/local/nginx

# tree /usr/local/nginx/
/usr/local/nginx/
|-- conf
|   |-- fastcgi.conf
|   |-- fastcgi.conf.default
|   |-- fastcgi_params
|   |-- fastcgi_params.default
|   |-- koi-utf
|   |-- koi-win
|   |-- mime.types
|   |-- mime.types.default
|   |-- nginx.conf                //主設定檔
|   |-- nginx.conf.default
|   |-- scgi_params
|   |-- scgi_params.default
|   |-- uwsgi_params
|   |-- uwsgi_params.default
|   `-- win-utf
|-- html
|   |-- 50x.html
|   `-- index.html
|-- logs
`-- sbin
    `-- nginx

3. 啟動
[[email protected] ~]# /usr/local/nginx/sbin/nginx
[[email protected] ~]# netstat -tnlp |grep :80
tcp        0      0 0.0.0.0:80        0.0.0.0:*            LISTEN      10627/nginx     

4. 測試
# links -dump 192.168.9.110
         Welcome to nginx!
# echo "/usr/local/nginx/sbin/nginx" >> /etc/rc.local         #開機運行


二、Nginx基本配置
[[email protected] ~]# vim /usr/local/nginx/conf/nginx.conf
CoreModule                       Nginx核心模組
EventsModule                     事件驅動模組
HttpCoreModule                   http核心模組

# sed -i ‘/^[ \t]*#/d;/^[ \t]*$/d‘ /usr/local/nginx/conf/nginx.conf

# vim /usr/local/nginx/conf/nginx.conf
worker_processes  2;                           #初始啟動的進程數(建議CPU的core數)
worker_connections  15000;                     #最大串連數
server {
        listen       80;                       #監聽的連接埠        
        server_name  localhost;                #網站名稱
        location / {
            root   html;                       #root指令指定網站主目錄(相對於nginx的安裝目錄)
            index  index.html index.htm;       #預設首頁
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}

語法檢查:
# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful


重新載入nginx:
[[email protected] ~]# pgrep nginx
5693
5757

[[email protected] ~]# kill -HUP 5693
[[email protected] ~]# pgrep nginx
5693
5787

# /usr/local/nginx/sbin/nginx -s reload

# /usr/local/nginx/html/                   #網站預設主目錄
# echo "Welcome to Jeffery Nginx" > /usr/local/nginx/html/index.html
[[email protected] ~]# elinks  -dump 192.168.9.110
   Welcome to Jeffery Nginx




========================================================

排錯:
[[email protected] ~]# /usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot
open shared object file: No such file or directory


編譯nginx指定  --with-pcre=/usr/src/pcre-8.31 指定pcre-8.31 的源碼路徑。

========================================================

本文出自 “Jeffery Blog” 部落格,請務必保留此出處http://oceanszf.blog.51cto.com/6268931/1539137

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.