介绍
Nginx是一款面向性能设计的HTTP服务器,相较于Apache、lighttpd具有占有内存少,稳定性高等优势。与旧版本(<=2.2)的Apache不同,Nginx不采用每客户机一线程的设计模型,而是充分使用异步逻辑从而削减了上下文调度开销,所以并发服务能力更强。整体采用模块化设计,有丰富的模块库和第三方模块库,配置灵活。
安装部署
安装依赖包
yum install -y gcc-c++ yum install -y pcre pcre-devel yum install -y zlib zlib-devel yum install -y openssl openssl-devel
此处采用源代码安装的方式:
nginx下载地址:http://nginx.org/en/download.html
http://nginx.org/download/nginx-1.17.6.tar.gz
wget http://nginx.org/download/nginx-1.17.6.tar.gz tar -zxvf nginx-1.17.6.tar.gz
在解压出来的nginx-1.17.6路径里面,执行下面的预编译。 path指定安装的路径。
./configure --prefix=/path make install
实际代码如下
./configure --prefix=/usr/src/nginx
然后会显示配置信息如下
Configuration summary + using system PCRE library + OpenSSL library is not used + using system zlib library nginx path prefix: "/usr/src/nginx" nginx binary file: "/usr/src/nginx/sbin/nginx" nginx modules path: "/usr/src/nginx/modules" nginx configuration prefix: "/usr/src/nginx/conf" nginx configuration file: "/usr/src/nginx/conf/nginx.conf" nginx pid file: "/usr/src/nginx/logs/nginx.pid" nginx error log file: "/usr/src/nginx/logs/error.log" nginx http access log file: "/usr/src/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"
期间如果出现类似如下报错,则是因为依赖包的问题,安装对应依赖包即可解决
./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.
由于我们已经在开头安装了相应依赖包,正常是不会出现类似报错,所以接着直接进入下一步
进行编译安装
make make install
进入sbin目录下,执行./nginx命令,即可启动。
cd /usr/src/nginx/sbin/ ./nginx
当然 直接使用/usr/src/nginx/sbin/nginx 也可以启动
启动后即可访问IP来访问默认页
如发现80端口不通,检查防火墙,添加放行80端口
firewall-cmd --add-port=80/tcp --permanent firewall-cmd --reload
站点目录默认是在nginx文件夹下的html
按如上配置的话就是在/usr/src/nginx/html/里
如需更改,可在/usr/src/nginx/conf/nginx.conf文件里修改root配置