Linux下安装Nginx并配置Nginx

责编:menVScode 2019-01-15 10:52 阅读(358)

1、安装 nginx(本文采用的版本是:nginx-1.8.1.tar.gz)

下载链接:http://nginx.org/en/download.html

2、根目录自建目录:/software,并上传安装包到此,解压:

tar -zxvf nginx-1.10.3.tar.gz

3、根目录下自建目录:/home/nginx,然后在 /software 目录下执行:

配置nginx安装目录命令:即配置安装环境,将会把Nginx安装到/project/nginx下;

./configure --prefix=/home/nginx

安装成功后 /home/nginx 目录下会出现一下文件:

[root@izbp12c0zpe8t4yri0xphiz nginx]# cd /project/nginx/
[root@izbp12c0zpe8t4yri0xphiz nginx]# ll
total 36
drwx------ 2 nobody root 4096 JAN  8 18:01 client_body_temp
drwxr-xr-x 2 root   root 4096 JAN  8 19:44 conf
drwx------ 2 nobody root 4096 JAN  8 18:01 fastcgi_temp
drwxr-xr-x 2 root   root 4096 JAN  8 17:33 html
drwxr-xr-x 2 root   root 4096 JAN  8 18:29 logs
drwx------ 2 nobody root 4096 JAN  8 18:01 proxy_temp
drwxr-xr-x 2 root   root 4096 JAN  8 17:33 sbin
drwx------ 2 nobody root 4096 JAN  8 18:01 scgi_temp
drwx------ 2 nobody root 4096 JAN  8 18:01 uwsgi_temp

4、如果是首次安装ngnix,可能就会没有以上文件,安装不成功

4.1 先安装 gcc

yum -y install gcc gcc-c++ autoconf automake make

4.2 若出现缺少依赖包则先安装依赖包,以下纯净centos mini版碰到的两个依赖包问题

./configure: error: the HTTP rewrite module requires the PCRE library. You can either disable the module by using --withou-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: error: the HTTP gzip module requires the zlib library. You can either disable the module by using --withou-http_gzip_module option, or install the zlib library into the system, or build the zlib library statically from the source with nginx by using --with-zlib=<path> option

出现上面问题,应执行下方命令安装依赖

yum install -y zlib-devel

4.3 在解压的文件夹下先后执行make 和 make install 命令进行编译,最后执行 yum -y install gcc gcc-c++ autoconf automake make 即可。


5、Nginx默认使用端口是80,执行 vi /home/nginx/conf/nginx.conf,修改server的端口

-- 按键盘【上下键】查看配置内容

-- 按键盘【Insert】键可对配置文件进行修改

-- 不保存退出:先按键盘【Esc】+ 【shift+:】+【q】+【enter】

-- 保存并退出:先按键盘【Esc】+ 【shift+:】+【wq】+【enter】

-- 强制退出:先按键盘【Esc】+ 【shift+:】+【q】+【shift+1】+【enter】


6、启动命令: 

/home/nginx/sbin/nginx -c /home/nginx/conf/nginx.conf

7、若修改了nginx.conf配置,则需要重启才生效,命令:

/home/nginx/sbin/nginx -s reload

8、启动成功后

微信截图_20190115121918


标签: Nginx Linux
前端交流群: MVC前端网(menvscode.com)-qq交流群:551903636

邮箱快速注册

忘记密码