一、使用CentOS7自带Yum安装Nginx
1、在安装Nginx前,先执行以下命令更新Yum源:
yum update
2、使用以下命令安装Nginx:
yum install nginx
3、安装完成后,使用以下命令启动Nginx:
systemctl start nginx
二、手动编译安装Nginx
1、下载Nginx源码包:
wget http://nginx.org/download/nginx-1.18.0.tar.gz
2、解压源码包:
tar zxvf nginx-1.18.0.tar.gz
3、进入解压后的目录:
cd nginx-1.18.0
4、执行以下命令编译Nginx:
(1)gcc
yum install gcc gcc-c++ -y
(2)prce
sudo yum install pcre pcre-devel
(3)zlib-devel
yum install -y zlib-devel
./configure --prefix=/usr/local/nginx
###输出nginx文件位置
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"
make
make install
5、安装完成后,使用以下命令启动Nginx:
/usr/local/nginx/sbin/nginx
三、配置Nginx
1、Nginx默认的配置文件为/etc/nginx/nginx.conf,在该文件中可以进行Nginx的相关配置,如IP和端口。
2、使用以下命令检查Nginx配置:
/usr/local/nginx/sbin/nginx -t
3、如果检查发现配置有误,使用以下命令重新加载配置:
/usr/local/nginx/sbin/nginx -s reload
四、测试Nginx是否运行正常
1、使用以下命令检查Nginx是否在运行:
ps aux | grep nginx
2、使用浏览器访问服务器IP或域名,如果出现“Welcome to nginx!”的页面,代表Nginx已安装成功。
五、Nginx常用命令
1、启动Nginx:
/usr/local/nginx/sbin/nginx
2、重新加载配置:
/usr/local/nginx/sbin/nginx -s reload
3、停止Nginx:
/usr/local/nginx/sbin/nginx -s stop
4、查看Nginx版本号:
/usr/local/nginx/sbin/nginx -v
5、查看Nginx的详细信息:
/usr/local/nginx/sbin/nginx -V
标签:sbin,http,nginx,安装,Nginx,usr,local From: https://www.cnblogs.com/mznsndy/p/17697946.html