nginx安装和配置

官方文档

http://nginx.org/download

下载

wget http://nginx.org/download/nginx-1.21.1.tar.gz

安装依赖包

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

解压

tar -zxvf nginx-1.21.1.tar.gz
cd nginx-1.21.1/

编译,安装

./configure --prefix=/usr/local/nginx
make && make install

查看安装目录:

whereis nginx

查看版本

/usr/local/nginx/sbin/nginx -v

启动

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

重启

/usr/local/nginx/sbin/nginx -s reload

停止

/usr/local/nginx/sbin/nginx -s stop

查看进程

ps -ef|grep nginx

测试,配置Nginx,新建存放项目目录,mkdir -p /data/test/html/,在此目录下新建文件index.html,打开Nginx配置文件,vim /usr/local/nginx/conf/nginx.conf,修改root指向配置,

location / {
        root   /data/test/html/;
        index  index.html index.htm;
}

重启Nginx,curl访问,查看是否能访问到index.html的内容

curl "http://127.0.0.1/"
//输出
test