linux如何安装nginx


本文摘自PHP中文网,作者藏色散人,侵删。

linux如何安装nginx?

在安装nginx前首先要确认系统中安装了gcc、pcre-devel、zlib-devel、openssl-devel。

相关推荐:【Linux教程】

安装命令:

1

yum -y install gcc pcre-devel zlib-devel openssl openssl-devel

nginx下载地址:https://nginx.org/download/

下载“nginx-1.9.9.tar.gz”,移动到/usr/local/下。

1

2

3

4

5

6

7

8

9

## 解压

tar -zxvf nginx-1.9.9.tar.gz

##进入nginx目录

cd nginx-1.9.9

## 配置

./configure --prefix=/usr/local/nginx

# make

make

make install

OK,现在可以执行make 了。

09539d98e652d4e993c6e36117bfb4f.png

执行make、make install命令

测试是否安装成功

1

2

# cd到刚才配置的安装目录/usr/loca/nginx/

./sbin/nginx -t

错误信息:

1

2

nginx: [alert] could not open error log file: open() "/usr/local/nginx/logs/error.log" failed (2: No such file or directory)

2016/09/13 19:08:56 [emerg] 6996#0: open() "/usr/local/nginx/logs/access.log" failed (2: No such file or directory)

原因分析:nginx/目录下没有logs文件夹

解决方法:

1

2

mkdir logs

chmod 700 logs

正常情况的信息输出:

1

2

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

启动nginx

1

2

cd /usr/local/nginx/sbin

./nginx //启动nginx

在浏览器中输入服务器的ip地址,如:192.168.1.12

很不幸,打不开链接。下面进行原因排查:

ca5004db67669a776d571f1d8086703.png

说明服务器的80端口是打不开的。

因为我使用的linux系统版本是CentOS7,所以可以在服务器中执行如下命令来验证》》

1

firewall-cmd --query-port=80/tcp

5bd59a39899d8a6f8603abb0401ec30.png

显然80端口没有开启。

下面我们开启80端口:

1

2

3

firewall-cmd --add-port=80/tcp --permanent

#重启防火墙

systemctl restart firewalld

--permanent #永久生效,没有此参数重启后失效

fb6a8d31fe77b99782171ce19e42f13.png

刷新浏览器

ee3f9c02727f190340fb553d9f9dabf.png

====================== 分割线 ====================

配置完毕!

2、配置nginx开机自启动

1

vim /etc/rc.d/rc.local

121c6f20a6878431c4172c6c52bc00f.png

更多Nginx相关技术文章,请访问Nginx使用教程栏目进行学习!

以上就是linux如何安装nginx的详细内容,更多文章请关注木庄网络博客

相关阅读 >>

nginx如何做负载均衡

怎么看nginx有没有启动

apache和nginx需要一起用吗

nginx如何处理http请求

nginx怎么跟php交互

centos系统下nginx启动不了怎么办

nginx是什么,做什么用的?

nginx与php怎么处理用户请求

linux如何重启nginx

nginx如何配置代理转发

更多相关阅读请进入《nginx》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...