欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

Nginx在Linux下的安装与配置

程序员文章站 2022-06-02 13:34:14
...
nginx依赖以下一些软件库,在安装之前请确保安装了这些软件库,它们包括:gcc,openssl,zlib,pcre(可通过rpm -q命令查询是否已安装),其中前三个库可通过系统盘进行安装,这里仅简单说说pcre的安装:

下载pcre至/home目录下,这里选择的版本是pcre-8.10,下载完后执行以下操作

[plain] view plaincopy

  1. 1.[root@localhost home]# tar zxvf pcre-8.10.tar.gz //解压缩
  2. 2.[root@localhost home]# cd pcre-8.10 //切换到该目录下
  3. 3.[root@localhost pcre-8.10]#./configure //配置
  4. 4.[root@localhost pcre-8.10]#make
  5. 5.[root@localhost pcre-8.10]#make install //安装


安装nginx

从nginx的官方网站下载稳定版本,这里下载的版本号是nginx-1.0.2。在默认情况下,经过编译安装的Nginx包含了大部分可用模块,可以通过“./configure --help”选项设置各个模块的使用情况,例如对不需要的http_ssi模块,可通过“--without-http_ssi_module”参数关闭此模块;如果需要“http_perl”模块,则可以通过“--with-http_perl_module”参数安装此模块。执行以下操作进行安装

[plain] view plaincopy

  1. 1.[root@localhost home]# tar zxvf nginx-1.0.2.tar.gz
  2. 2.[root@localhost home]#cd nginx-1.0.2
  3. 3.[root@localhostnginx-1.0.2]#./configure --with-http_stub_status_module --prefix=/usr/local/nginx
  4. 4.[root@localhost nginx-1.0.2]#make
  5. 5.[root@localhost nginx-1.0.2]#make install

配置时使用"with-http_stub_status_module"参数来启用 Nginx 的 NginxStatus 功能,以监控 Nginx 的当前状态。

安装完成后执行以下操作验证安装是否成功:

[plain] view plaincopy

  1. cd /usr/local/nginx/sbin
  2. ./nginx -t

结果显示:
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的安装已成功完成。

启动nginx
cd /usr/local/nginx/sbin
./nginx //启动nginx
在浏览器中输入:http://localhost验证nginx是否成功启动

停止nginx
pkill -9 nginx

以上就介绍了Nginx在Linux下的安装与配置,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。