centos6.5 安裝nginx1.10.2

Nginx 官方網站 www.nginx.org

第一步:在/usr/local下創建nginx目錄並進入
(1 ) mkdir /usr/local/nginx
(2)cd /usr/local/nginx
下載nginx相應的版本,wget 版本路徑例如:
(3)wget http://nginx.org/download/nginx-1.10.2.tar.gz

第二步:解壓:
(4)tar zxvf nginx-1.10.2.tar.gz
第三步執行配置初始化:進入解壓文件夾 nginx
(5)[root@vw010001135067 local]# cd nginx-1.10.2
(6)[root@vw010001135067 nginx-1.10.2]#./configure --help 可以查看configure 的參數寫法以及相應的參數
(7) [root@vw010001135067 nginx-1.10.2]#./configure --prefix=/usr/local/nginx 配置nginx的安裝路徑
執行configure配置不成功遇到的問題:報錯如下:
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

出現這個錯誤。那麼就是gcc 包沒有安裝。
1.3.1 安裝gcc
查看gcc命令
[root@vw010001135067 nginx-1.10.2]# whereis gcc
gcc:
安裝gcc
[root@vw010001135067 nginx-1.10.2]# yum -y install 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 繼續執行./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.
出現如上錯誤。安裝pcre-devel
[root@vw010001135067 nginx-1.10.2]# yum install pcre-devel
1.3.3 再次執行./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.
如果有這個錯誤 那麼執行
yum install zlib-devel
1.3.4 執行./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
 + 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 開啓ssl 模塊 執行./configure –with-http_ssl_module
[root@vw010001135067 nginx-1.10.2]# ./configure --with-http_ssl_module
1.4.2 啓用“server+status”頁,執行./configure –with-http_stub_status_module
1 [root@vw010001135067 nginx-1.10.2]# ./configure --with-http_stub_status_module
上面兩個命令同時啓動可以
1 [root@vw010001135067 nginx-1.10.2]# ./configure --with-http_stub_status_module --with-http_ssl_module
1.5 上面configure就通過了
執行make 命令,執行make install 命令
[root@vw010001135067 nginx-1.10.2]# make
[root@vw010001135067 nginx-1.10.2]# make install
至此,nginx 執行成功了
1.6 配置環境變量
在/etc/profile 中加入配置 
打開配置文件
1 [root@vw010001135067 nginx-1.10.2]# vi /etc/profile
在配置文件中加入
1
2
3 #nginx configure
export NGINX_HOME=/usr/local/nginx-1.10.2
export PATH=PATH:PATH:NGINX_HOME/sbin
我開始像上面填寫,結果nginx -v的時候查找不到。注意到上面我的nginx_home配置的地址不對。先找到nginx的安裝地址
1
2 [root@vw010001135067 nginx-1.10.2]# whereis nginx
nginx: /usr/local/nginx
還真是地址寫錯了,把上面的改成
1
2
3 #nginx configure
export NGINX_HOME=/usr/local/nginx
export PATH=PATH:PATH:NGINX_HOME/sbin
編譯完保存退出並執行
1 [root@vw010001135067 nginx-1.10.2]# source /etc/profile

使配置生效。
1.7 查看nginx版本
1
2 [root@vw010001135067 nginx]# nginx -v
nginx version: nginx/1.10.2
整個過程成功了!
2.1 啓動nginx
我的nginx服務在http://10.1.135.67/,配置成功後,現在啓動nginx
[root@vw010001135067 nginx]# cd /usr/local/nginx
[root@vw010001135067 nginx]# nginx -c conf/nginx.conf
啓動成功,在瀏覽器打開http://10.1.135.67/,默認端口號80.

如上圖,nginx已經正常工作了。
遇到問題:瀏覽器訪問不通的問題

很多時候,安裝完成後,服務也啓動了
但是訪問不了
看看是不是防火牆開啓了;
本地試下端口是否可訪問telnet 192.168.4.155 80

本地機器測試nginx是否能正常啓動
所謂的本地機器,就是你安裝了nginx軟件的那一臺機器,輸入命令:
curl http://192.168.241.129/
這裏的ip地址爲你本機的ip地址然後會有結果:
[root@localhost nginx-1.12.1]# curl http://192.168.241.129/

Welcome to nginx!

Welcome to nginx!

If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.

For online documentation and support please refer tonginx.org.
Commercial support is available atnginx.com.

Thank you for using nginx.

[root@localhost nginx-1.12.1]# 以上驗證了本地是已經安裝成功的了, 但是我們遠程訪問的時候就是訪問不了,一直說拒絕訪問,那就是可能真的跟端口,防火牆有關了。 防火牆、端口開啓設置 打開80端口: vi /etc/sysconfig/iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT CentOS 7默認使用的是firewall作爲防火牆,這裏改爲iptables防火牆。 firewall: systemctl start firewalld.service#啓動firewall systemctl stop firewalld.service#停止firewall systemctl disable firewalld.service#禁止firewall開機啓動

Iptables stop

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章