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= P A T H : 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= P A T H : 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

猜你喜欢

转载自blog.csdn.net/weixin_43025071/article/details/83342038