Ubuntu系統 Nginx安裝及配置
阿新 • • 發佈:2018-11-29
首先,登入ubuntu系統
首先需安裝nginx依賴庫
1.安裝gcc g++的依賴庫
apt-get install build-essential apt-get install libtool
2.安裝pcre依賴庫
sudo apt-get update sudo apt-get install libpcre3 libpcre3-dev
3.安裝zlib依賴庫
apt-get install zlib1g-dev
4.安裝ssl依賴庫
apt-get install openssl
安裝nginx
#下載最新版本: wget http://nginx.org/download/nginx-1.11.3.tar.gz #解壓: tar -zxvf nginx-1.11.3.tar.gz #進入解壓目錄: cd nginx-1.11.3 #配置: ./configure --prefix=/usr/local/nginx #編輯nginx: make 注意:這裡可能會報錯,提示“pcre.h No such file or directory”,具體詳見:http://stackoverflow.com/questions/22555561/error-building-fatal-error-pcre-h-no-such-file-or-directory 需要安裝 libpcre3-dev,命令為:sudo apt-get install libpcre3-dev #安裝nginx: sudo make install #啟動nginx: sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 注意:-c 指定配置檔案的路徑,不加的話,nginx會自動載入預設路徑的配置檔案,可以通過 -h檢視幫助命令。 #檢視nginx程序: ps -ef|grep nginx
配置nginx
cd /usr/local/nginx/conf/
使用vim或nano編輯器在該目錄下新建一個ihasy.conf檔案輸入以下內容:
upstream ihasy { server 127.0.0.1:9001; #Tornado } ## Start www.ihasy.com ## server { listen 80; server_name www.ihasy.com ihasy.com; #root html; #index index.html index.htm index.py index; ## send request back to Tornado ## location / { proxy_pass http://ihasy; #Proxy Settings proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; proxy_max_temp_file_size 0; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; } } ## End www.ihasy.com ##
再使用vim或nano開啟 /usr/local/nginx/conf/nginx.conf
nano /usr/local/nginx/conf/nginx.conf
在http下新增一行
include ihasy.conf
儲存,重啟nginx,即可實現反向代理。
上傳檔案大小設定
client_max_body_size 屬性設定
location ~ [^/]\.php(/|$) { include fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; client_max_body_size 500m; }