時間:2015-11-16 23:39 作者:明源網絡
安裝
ubuntu下
1 |
sudo apt-get install nginx |
啟動
1 2 |
sudo /etc/init.d/nginx start sudo service nginx start |
設置文件位置
編譯安裝
1.先決條件
(1).gcc
(2).pcre(Perl Compatible Regular Expression)
1 |
apt-get install libpcre3 libpcre3-dev |
(3).zlib
1 |
apt-get install zliblg zliblg-dev |
(4).openssl
1 2 3 |
apt-get install openssl opensll-dev |
2.下載包
www.nginx.net 下載不變版
1 |
wget http://nginx.org/download/nginx-1.4.4.tar.gz |
3.解壓安裝
1 2 3 4 5 6 7 8 |
tar -xzvf nginx-1.4.4.tar.gz ./configure make make install ./configure --conf-path=/etc/nginx/nginx.conf |
可以設置一些其他選項
安裝后查察下目次下的Configuration summary
4.init劇本
需要給nginx成立一個init劇本
從網上撈一個,放入/etc/init.d/nginx
推薦編譯設置
1.利用差異prefix,利便指定差異版本,也便于進級
1 |
./configure --prefix=/usr/local/nginx-1.4.4 |
根基操縱
查察輔佐
1 |
/usr/local/nginx/sbin/nginx -h |
當即遏制歷程(TERM信號)
1 |
/usr/local/nginx/sbin/nginx -s stop |
溫和遏制歷程(QUIT信號)
1 |
/usr/local/nginx/sbin/nginx -s quit |
重加載
1 2 |
/etc/init.d/nginx reload /usr/local/nginx/sbin/nginx -s reload |
檢測設置文件是否正確
1 2 |
/usr/local/nginx/sbin/nginx -t /usr/local/nginx/sbin/nginx -t -c /home/ken/tmp/test.conf |
HTTP根基設置
設置說明
注釋,#
每條指令老是以分好竣事(;)
設置擔任:在一個區塊中嵌套其他區段,那么被嵌套的區段會擔任其父區段的配置
字符串,可以沒有引號,可是假如存在非凡字符(空格,分號,花括號)需要用引號引起
單元:巨細(k/K m/M) 時間值(ms/s/m/h/d/w/M/y 默認s)
模塊提供各類變量值,可以舉辦讀取和賦值(每個模塊提供變量列表需要本身去查)
設置文件目次布局
/usr/local/nginx/conf/
- mime.types 一個文件擴展列表,它們與MIME范例關聯
- fastcgi.conf 與FastCGI相關的設置文件
- proxy.conf 與Proxy相關的設置文件
- nginx.conf 應用措施的根基設置文件
- sites/
|- a.conf #答允給每個單獨網站成立一個設置文件
|- b.conf
|- dir/
|- c.conf
需要在nginx.conf中利用包括呼吁
1 2 |
include sites/*.conf; include sites/*/*.conf; |
設置文件布局
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
http { #嵌入設置文件的根部, 一個http里可以設置多個server server { #聲明一個站點 server_name www.website.com; #監聽的主機名 listen 80; #監聽套接字所利用的ip地點和端標語 error_page 404 /not_found.html; error_page 500 501 502 503 504 /server_error.html; index index.html; root /var/www/website/com/html; #界說文檔的根目次 #location, 通過擬定的模式與客戶端請求的URI相匹配 location / { #網站的特定位置 } location /admin/ { #網站的特定位置 # alias /var/www/locked/; #只能放在 location區段中,為指定路徑提供別名 } #操縱符,匹配時跟界說順序無關 location = /abcd { #準確匹配,不能用正則 } location /abc/ { #url必需以指定模式開始,不能用正則 } location ^~ /abcd$ { #吳標致行為,URI定位必需以指定模式開始,假如匹配,遏制搜索其他模式 } location ~ ^/abcd$ { #正則匹配,區分巨細寫 } location ~* ^/abcd$ { #正則匹配,,不區分巨細寫 } location @test { #界說location區段名,客戶端不能會見,內部發生的請求可以,譬喻try_files或error_page } } } |