一特碳、Linux下安裝配置nginx
第一次安裝nginx,中間出現(xiàn)的問(wèn)題一步步解決诚亚。
用到的工具secureCRT,連接并登錄服務(wù)器午乓。
1.1 rz命令站宗,會(huì)彈出會(huì)話框,選擇要上傳的nginx壓縮包益愈。
???? #rz
1.2 解壓
[root@vw010001135067 ~]# cd /usr/local/
[root@vw010001135067 local]# tar -zxvf nginx-1.10.2.tar.gz
1.3 進(jìn)入nginx文件夾梢灭,執(zhí)行./configure命令
[root@vw010001135067 local]# cd nginx-1.10.2
[root@vw010001135067 nginx-1.10.2]# ./configure
報(bào)錯(cuò)如下:
checking for OS
+ Linux 2.6.32-431.el6.x86_64 x86_64
checking for C compiler ... not found
./configure: error: C compiler cc is not found
出現(xiàn)這個(gè)錯(cuò)誤。那么就是gcc 包沒(méi)有安裝蒸其。
1.3.1 安裝gcc
查看gcc
[root@vw010001135067 nginx-1.10.2]# whereis gcc
gcc:
安裝gcc
[root@vw010001135067 nginx-1.10.2]# whereis gcc
gcc: /usr/bin/gcc /usr/lib/gcc /usr/libexec/gcc /usr/share/man/man1/gcc.1.gz
gcc安裝好了敏释。
1.3.2 繼續(xù)執(zhí)行./configure
[root@vw010001135067 nginx-1.10.2]# ./configure
checking for OS
+ Linux 2.6.32-431.el6.x86_64 x86_64
checking for C compiler ... found
......
checking for PCRE library ... not found
checking for PCRE library in /usr/local/ ... not found
checking for PCRE library in /usr/include/pcre/ ... not found
checking for PCRE library in /usr/pkg/ ... not found
checking for PCRE library in /opt/local/ ... not found
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre= option.
出現(xiàn)如上錯(cuò)誤。安裝pcre-devel
[root@vw010001135067 nginx-1.10.2]# yum install pcre-devel
1.3.3 再次執(zhí)行./configure
error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib= option.
如果有這個(gè)錯(cuò)誤 那么執(zhí)行
yum install zlib-devel
1.3.4 執(zhí)行./configure后沒(méi)有報(bào)錯(cuò)
[root@vw010001135067 nginx-1.10.2]# ./configure
checking for OS
+ Linux 2.6.32-431.el6.x86_64 x86_64
checking for C compiler ... found
+ using GNU C compiler
+ gcc version: 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC)
.......
Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ md5: using system crypto library
+ sha1: using system crypto library
+ using system zlib library
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
1.4 如果你想使用openssl 功能枣接,sha1 功能。 那么安裝openssl 缺谴,sha1 吧
[root@vw010001135067 nginx-1.10.2]# yum install openssl openssl-devel
[root@vw010001135067 nginx-1.10.2]# install perl-Digest-SHA1.x86_64
1.4.1 開(kāi)啟ssl 模塊 執(zhí)行./configure –with-http_ssl_module
[root@vw010001135067 nginx-1.10.2]# ./configure --with-http_ssl_module
1.4.2 啟用“server+status”頁(yè)但惶,執(zhí)行./configure –with-http_stub_status_module
[root@vw010001135067 nginx-1.10.2]# ./configure --with-http_stub_status_module
上面兩個(gè)命令同時(shí)啟動(dòng)可以
代碼如下:
[root@vw010001135067 nginx-1.10.2]# ./configure --with-http_stub_status_module --with-http_ssl_module
1.5 上面configure就通過(guò)了
執(zhí)行make 命令耳鸯,執(zhí)行make install 命令
[root@vw010001135067 nginx-1.10.2]# make
[root@vw010001135067 nginx-1.10.2]# make install
至此,nginx 執(zhí)行成功了
1.6 配置環(huán)境變量
在/etc/profile 中加入配置
打開(kāi)配置文件
[root@vw010001135067 nginx-1.10.2]# vi /etc/profile
在配置文件中加入
#nginx configure
export NGINX_HOME=/usr/local/nginx-1.10.2
export PATH=$PATH:$NGINX_HOME/sbin
我開(kāi)始像上面填寫(xiě)膀曾,結(jié)果nginx -v的時(shí)候查找不到县爬。注意到上面我的nginx_home配置的地址不對(duì)。先找到nginx的安裝地址
[root@vw010001135067 nginx-1.10.2]# whereis nginx
nginx: /usr/local/nginx
還真是地址寫(xiě)錯(cuò)了添谊,把上面的改成
#nginx configure
export NGINX_HOME=/usr/local/nginx
export PATH=$PATH:$NGINX_HOME/sbin
編譯完保存退出并執(zhí)行
[root@vw010001135067 nginx-1.10.2]# source /etc/profile
使配置生效财喳。
1.7 查看nginx版本
[root@vw010001135067 nginx]# nginx -v
nginx version: nginx/1.10.2
整個(gè)過(guò)程成功了!
二斩狱、修改nginx.conf
2.1 啟動(dòng)nginx
我的nginx服務(wù)在http://10.1.135.67/耳高,配置成功后,現(xiàn)在啟動(dòng)nginx
[root@vw010001135067 nginx]# cd /usr/local/nginx
[root@vw010001135067 nginx]# nginx -c conf/nginx.conf
啟動(dòng)成功所踊,在瀏覽器打開(kāi)http://10.1.135.67/泌枪,默認(rèn)端口號(hào)80.
如上圖,nginx已經(jīng)正常工作了秕岛。
2.2 配置tomcat服務(wù)
現(xiàn)在我的tomcat服務(wù)在10.1.29.15碌燕,需要通過(guò)nginx轉(zhuǎn)發(fā)。那么打開(kāi)nginx.conf继薛,修改配置文件修壕。如下,添加:
#user nobody;#指定使用的用戶
worker_processes? 1;#開(kāi)啟的進(jìn)程數(shù)遏考,一般設(shè)置CUP核心數(shù) 或者核心數(shù)量*2
#定義錯(cuò)誤日志慈鸠,以及記錄的日志等級(jí)
#error_log? logs/error.log;
#error_log? logs/error.log? notice;
#error_log? logs/error.log? info;
#pid? ? ? ? logs/nginx.pid;
events {
worker_connections? 1024;#單個(gè)進(jìn)程最大連接數(shù)(最大連接數(shù)=連接數(shù)*進(jìn)程數(shù))
#use [ kqueue | rtsig | epoll | /dev/poll | select | poll ];
#use epoll; #使用epoll(linux2.6的高性能方式)
}
http {
include? ? ? mime.types; #文件擴(kuò)展名與文件類(lèi)型映射表
default_type? application/octet-stream;#默認(rèn)文件類(lèi)型
#指定日志格式
#log_format? main? '$remote_addr - $remote_user [$time_local] "$request" '
#? ? ? ? ? ? ? ? ? '$status $body_bytes_sent "$http_referer" '
#? ? ? ? ? ? ? ? ? '"$http_user_agent" "$http_x_forwarded_for"';
#指定日志存放路徑
#access_log? logs/access.log? main;
sendfile? ? ? ? on;#開(kāi)啟高效文件傳輸模式,sendfile指令指定nginx是否調(diào)用sendfile函數(shù)來(lái)輸出文件诈皿,對(duì)于普通應(yīng)用設(shè)為 on林束,如果用來(lái)進(jìn)行下載等應(yīng)用磁盤(pán)IO重負(fù)載應(yīng)用,可設(shè)置為off稽亏,以平衡磁盤(pán)與網(wǎng)絡(luò)I/O處理速度壶冒,降低系統(tǒng)的負(fù)載。注意:如果圖片顯示不正常把這個(gè)改成off截歉。
#tcp_nopush? ? on;#該選項(xiàng)用于防止網(wǎng)絡(luò)阻塞
#keepalive_timeout? 0;
keepalive_timeout? 65; #長(zhǎng)連接超時(shí)時(shí)間胖腾,單位是秒
gzip? on;#啟用Gizp壓縮
#服務(wù)器的集群
upstream? log.5i5j.com { #服務(wù)器集群名字
#server? 172.16.21.13:8081 weight=1;#服務(wù)器配置? weight是權(quán)重的意思,權(quán)重越大瘪松,分配的概率越大咸作。
#server? 127.0.0.1:8080? weight=1;
server? ? 10.9.2.49:28778 weight=1;
}
#當(dāng)前的Nginx的配置
server {
listen? ? ? 80;#監(jiān)聽(tīng)80端口,可以改成其他端口
server_name? log.5i5j.com;#當(dāng)前服務(wù)的域名
#charset koi8-r;#默認(rèn)字符編碼
#access_log? logs/host.access.log? main;
#pass路徑匹配 能夠匹配路徑中帶“/”的 不過(guò)需要注意的是如果之后也有相關(guān)“/”匹配項(xiàng)并且使用比此處更精確匹配符宵睦,則以之后表達(dá)式優(yōu)先
#location / {
#? ? root? html;
#? ? index? index.html index.htm;access_log off;
#? ? access_log off; #關(guān)閉日志
#}
location / {
proxy_pass http://log.5i5j.com;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_redirect default;
proxy_connect_timeout 9000; #nginx跟后端服務(wù)器連接超時(shí)時(shí)間(代理連接超時(shí))
proxy_send_timeout 9000; #后端服務(wù)器數(shù)據(jù)回傳時(shí)間(代理發(fā)送超時(shí))
proxy_read_timeout 9000; #連接成功后记罚,后端服務(wù)器響應(yīng)時(shí)間(代理接收超時(shí))
}
location ~ ^/WEB-INF/ {
deny? all;
}
#圖片緩存時(shí)間設(shè)置
#location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$ {
# expires 10d;
# root /opt/webRoot/xxx.xxx.com.static.images;
#}
#JS和CSS緩存時(shí)間設(shè)置
#location ~ .*.(js|css)?$ {
# expires 1h;
# root /opt/webRoot/xxx.xxx.com.static.js;
#}
#對(duì) "/" 啟用反向代理
#location / {
# proxy_pass http://127.0.0.1:88;
# proxy_redirect off;
# proxy_set_header X-Real-IP $remote_addr;
# #后端的Web服務(wù)器可以通過(guò)X-Forwarded-For獲取用戶真實(shí)IP
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# #以下是一些反向代理的配置,可選壳嚎。
# proxy_set_header Host $host;
# client_max_body_size 10m; #允許客戶端請(qǐng)求的最大單文件字節(jié)數(shù)
# client_body_buffer_size 128k; #緩沖區(qū)代理緩沖用戶端請(qǐng)求的最大字節(jié)數(shù)桐智,
# proxy_connect_timeout 90; #nginx跟后端服務(wù)器連接超時(shí)時(shí)間(代理連接超時(shí))
# proxy_send_timeout 90; #后端服務(wù)器數(shù)據(jù)回傳時(shí)間(代理發(fā)送超時(shí))
# proxy_read_timeout 90; #連接成功后末早,后端服務(wù)器響應(yīng)時(shí)間(代理接收超時(shí))
# proxy_buffer_size 4k; #設(shè)置代理服務(wù)器(nginx)保存用戶頭信息的緩沖區(qū)大小
# proxy_buffers 4 32k; #proxy_buffers緩沖區(qū),網(wǎng)頁(yè)平均在32k以下的設(shè)置
# proxy_busy_buffers_size 64k; #高負(fù)荷下緩沖大兴低ァ(proxy_buffers*2)
# proxy_temp_file_write_size 64k;
# #設(shè)定緩存文件夾大小然磷,大于這個(gè)值,將從upstream服務(wù)器傳
#}
#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;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ { # "~ $"正則表達(dá)式匹配 一旦匹配則不再向下匹配
#? ? proxy_pass? http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
#? ? root? ? ? ? ? html;
#? ? fastcgi_pass? 127.0.0.1:9000;
#? ? fastcgi_index? index.php;
#? ? fastcgi_param? SCRIPT_FILENAME? /scripts$fastcgi_script_name;
#? ? include? ? ? ? fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#? ? deny? all;
#}
#location ~* \.(txt|doc)$ { # "~*" 代表不區(qū)分大小寫(xiě)方式匹配
#? ? deny? all;#不希望訪問(wèn)txt|doc文件
#}
}
}
配置好后姿搜,保存配置文件,并且重啟nginx
[root@vw010001135067 nginx]# nginx -s reload
在瀏覽器調(diào)用upload項(xiàng)目是否成功
如圖能正確訪問(wèn)項(xiàng)目捆憎,配置成功舅柜!
原文鏈接:http://blog.csdn.net/u010416588/article/details/54379282