1、完整干净的vps centos7
新开的centos7 vps,先update一下
yum update
2、安装最新版的nginx 1.18.0
先安装wget
yum install wget
wget http://nginx.org/download/nginx-1.18.0.tar.gz
解压缩下载下来的nginx
tar -zvxf nginx-1.18.0.tar.gz
进入nginx目录
cd nginx-1.18.0
nginx有很多编译配置项,我使用了默认的配置:
./configure --with-http_ssl_module --with-http_gzip_static_module
。。。
nginx path prefix: “/usr/local/nginx”
nginx binary file: “/usr/local/nginx/sbin/nginx”
nginx modules path: “/usr/local/nginx/modules”
nginx configuration prefix: “/usr/local/nginx/conf”
nginx configuration file: “/usr/local/nginx/conf/nginx.conf”
nginx pid file: “/usr/local/nginx/logs/nginx.pid”
nginx error log file: “/usr/local/nginx/logs/error.log”
nginx http access log file: “/usr/local/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”
上面是nginx各类文件的名称及路径。
上图可以看见,有好多文件在编译过程中出现(…not found),是因为缺少依赖的问题,最常用的依赖
gcc zlib ssl等
yum install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
make
make install
3、启动nginx:
启动nginx:
cd /usr/local/nginx/sbin/
./nginx
如果运行的时候不带-c参数,那就采用默认的配置文件,即/etc/nginx/nginx.conf
查看运行进程状态:
ps aux | grep nginx
打开浏览器,访问http://localhost/看看nginx的默认页面:
停止nginx:
./nginx -s stop
重启nginx(配置文件变动后需要重启才能生效):
./nginx -s reload
检查配置文件是否正确:
./nginx -t
查看nginx的pid:
cat /usr/local/nginx/logs/nginx.pid
查看nginx版本
./nginx -v
回头看编译配置
./nginx -V