步骤是网上百度的(亲测有效)
yum install gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
安装(注意:没有进入文件夹的话会直接安装在根目录下)
解压
tar -zxvf nginx-1.8.0.tar.gz
使用默认配置
./configure
或者使用自定义配置 (不建议,下面的/var/temp/是自己要建立的路径)
./configure
–prefix=/usr/local/nginx
–conf-path=/usr/local/nginx/conf/nginx.conf
–pid-path=/usr/local/nginx/conf/nginx.pid
–lock-path=/var/lock/nginx.lock
–error-log-path=/var/log/nginx/error.log
–http-log-path=/var/log/nginx/access.log
–with-http_gzip_static_module
–http-client-body-temp-path=/var/temp/nginx/client
–http-proxy-temp-path=/var/temp/nginx/proxy
–http-fastcgi-temp-path=/var/temp/nginx/fastcgi
–http-uwsgi-temp-path=/var/temp/nginx/uwsgi
–http-scgi-temp-path=/var/temp/nginx/scgi
编译安装
make
makeinstall
查看一下配置是否有错误
./nginx -t
查看一下啊nginx的安装路径
whereis nginx
去到该路径下 (一般默认在这里)
cd /usr/local/nginx/sbin
启动
./nginx
重启 【配置文件修改了使用该命令后会直接生效,不用先关闭nginx】
./nginx -s reload
关闭nginx 【待nginx结束自己的任务进程后关闭】
./nginx -s quit
关闭nginx 【查找出nginx的id再强制kill】
./nginx -s stop
查看一下nginx的进程
ps -ef|grep nginx
注意一下,要记得开放阿里云的安全组规则
并且关闭一下linux的防火墙:
systemctl stop firewalld.service
然后查看一下防火墙的状态
systemctl status firewalld
然后可以自己在服务器里手动访问一下
curl 39.96.33.*** (ip地址)
或者在网页上访问一下ip地址
可以设置开机自启: 在根目录下的/etc/
vim /etc/rc.local
加上
/usr/local/nginx/sbin/nginx
然后执行配置下执行权限
chmod 755 rc.local
chmod 755 设置用户的权限为:
1.文件所有者可读可写可执行
2.与文件所有者同属一个用户组的其他用户可读可执行
3.其它用户组可读可执行
重启一下服务器:
shutdown -r now
再次访问nginx,依旧可以访问到,说明开机自启设置成功了。
因为 Nginx是我们自己手动编译安装的,所以有可能存在有两个配置文件的情况,一个是解压后的路径下,一个是/usr/local/nginx下 ,如果我们不清楚系统生效的哪个配置文件可以使用如下命令查看(这里显示的是/usr/local/nginx生效,所以我把解压后的/opt/下的Nginx删除了,发现nginx照常运行,并无影响)
ps -aux|grep nginx
这样nginx就配置完成了。