Nginx處事器的安裝與一些根基設(shè)置總結(jié)
時(shí)間:2015-11-16 23:39 作者:明源網(wǎng)絡(luò)
安裝
ubuntu下
1 |
sudo apt-get install nginx |
啟動(dòng)
1 2 |
sudo /etc/init.d/nginx start sudo service nginx start |
設(shè)置文件位置
編譯安裝
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 |
可以設(shè)置一些其他選項(xiàng)
安裝后查察下目次下的Configuration summary
4.init劇本
需要給nginx成立一個(gè)init劇本
從網(wǎng)上撈一個(gè),放入/etc/init.d/nginx
推薦編譯設(shè)置
1.利用差異prefix,利便指定差異版本,也便于進(jìn)級(jí)
1 |
./configure --prefix=/usr/local/nginx-1.4.4 |
根基操縱
查察輔佐
1 |
/usr/local/nginx/sbin/nginx -h |
當(dāng)即遏制歷程(TERM信號(hào))
1 |
/usr/local/nginx/sbin/nginx -s stop |
溫和遏制歷程(QUIT信號(hào))
1 |
/usr/local/nginx/sbin/nginx -s quit |
重加載
1 2 |
/etc/init.d/nginx reload /usr/local/nginx/sbin/nginx -s reload |
檢測(cè)設(shè)置文件是否正確
1 2 |
/usr/local/nginx/sbin/nginx -t /usr/local/nginx/sbin/nginx -t -c /home/ken/tmp/test.conf |
HTTP根基設(shè)置
設(shè)置說(shuō)明
注釋?zhuān)?
每條指令老是以分好竣事(;)
設(shè)置擔(dān)任:在一個(gè)區(qū)塊中嵌套其他區(qū)段,那么被嵌套的區(qū)段會(huì)擔(dān)任其父區(qū)段的配置
字符串,可以沒(méi)有引號(hào),可是假如存在非凡字符(空格,分號(hào),花括號(hào))需要用引號(hào)引起
單元:巨細(xì)(k/K m/M) 時(shí)間值(ms/s/m/h/d/w/M/y 默認(rèn)s)
模塊提供各類(lèi)變量值,可以舉辦讀取和賦值(每個(gè)模塊提供變量列表需要本身去查)
設(shè)置文件目次布局
/usr/local/nginx/conf/
- mime.types 一個(gè)文件擴(kuò)展列表,它們與MIME范例關(guān)聯(lián)
- fastcgi.conf 與FastCGI相關(guān)的設(shè)置文件
- proxy.conf 與Proxy相關(guān)的設(shè)置文件
- nginx.conf 應(yīng)用措施的根基設(shè)置文件
- sites/
|- a.conf #答允給每個(gè)單獨(dú)網(wǎng)站成立一個(gè)設(shè)置文件
|- b.conf
|- dir/
|- c.conf
需要在nginx.conf中利用包括呼吁
1 2 |
include sites/*.conf; include sites/*/*.conf; |
設(shè)置文件布局
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 { #嵌入設(shè)置文件的根部, 一個(gè)http里可以設(shè)置多個(gè)server server { #聲明一個(gè)站點(diǎn) server_name www.website.com; #監(jiān)聽(tīng)的主機(jī)名 listen 80; #監(jiān)聽(tīng)套接字所利用的ip地點(diǎn)和端標(biāo)語(yǔ) 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; #界說(shuō)文檔的根目次 #location, 通過(guò)擬定的模式與客戶端請(qǐng)求的URI相匹配 location / { #網(wǎng)站的特定位置 } location /admin/ { #網(wǎng)站的特定位置 # alias /var/www/locked/; #只能放在 location區(qū)段中,為指定路徑提供別名 } #操縱符,匹配時(shí)跟界說(shuō)順序無(wú)關(guān) location = /abcd { #準(zhǔn)確匹配,不能用正則 } location /abc/ { #url必需以指定模式開(kāi)始,不能用正則 } location ^~ /abcd$ { #吳標(biāo)致行為,URI定位必需以指定模式開(kāi)始,假如匹配,遏制搜索其他模式 } location ~ ^/abcd$ { #正則匹配,區(qū)分巨細(xì)寫(xiě) } location ~* ^/abcd$ { #正則匹配,,不區(qū)分巨細(xì)寫(xiě) } location @test { #界說(shuō)location區(qū)段名,客戶端不能會(huì)見(jiàn),內(nèi)部發(fā)生的請(qǐng)求可以,譬喻try_files或error_page } } } |