nginx是一种高效的支持高并发的轻量级服务器,它还可以用来做反向代理和负载均衡。
Linux配置nginx的步骤如下:
一,到https://nginx.org/en/download.html 页面下载最新的稳定版本的包( 我下的是nginx-1.10.1.tar.gz)并上传至Linux某个目录后解压。
tar -zvxf nginx-1.10.1.tar.gz
然后进入解压后的目录执行./configure
提示错误:
[root@VM_126_4_centos nginx-1.10.1]# ./configure
checking for OS
+ Linux 2.6.32-431.23.3.el6.centos.plus.x86_64 x86_64
checking for C compiler ... not found
./configure: error: C compiler cc is not found
执行
yum install gcc gcc-c++ ncurses-devel perl
提示错误:
./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=<path> option.
执行, yum -y install pcre-devel,再次./configure
成功
二,在nginx目录依次执行,make, make install 。
查看/usr/local/文件夹下有没有nginx
[root@dn3 nginx-1.10.1]# ls /usr/local/
agenttools nginx qcloud sa services
有,说明安装成功
三,启动nginx
首先编辑配置文件,将端口修改为8086,vim /usr/local/nginx/conf/nginx.conf
server {
listen 8086;
server_name localhost;
然后启动
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
没反应后,测试
[root@dn3 ~]# curl http://localhost:8086/
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
成功!
tips:
windows 系统下,只需将nginx-1.10.1.zip解压,然后进入解压后的文件夹nginx-1.10.1
双击nginx.exe即可
然后再自己浏览器中访问地址http://localhost/
返回页面如下则表示成功运行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 to nginx.org.
Commercial support is available at nginx.com.
Thank you for using nginx.