1、下载地址
2、将下载好的tar包上传到/opt下。
3、解压tar包
tar -xvf nginx-1.24.0.tar.gz
4、进入安装包目录
cd /opt/nginx-1.24.0
//编译
./configure --prefix=/opt/nginx --with-http_stub_status_module --with-http_ssl_module
//安装
make && make install
5、进入Nginx安装位置
cd /opt/nginx
6、修改nginx.conf(注:不修改会出现curl http://localhost 时返回403)
vi /conf/nginx.conf
原文
#user nobody;
worker_processes 1;
修改为如下:
user root;
worker_processes auto;
server {
listen 80;
listen [::]:80;
server_name _;
root /opt/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
root html;
index index.html;
}
7、启动
cd /opt/nginx/sbin
# 启动nginx
./nginx
# 校验nginx.conf是否有问题(返回的出现字眼“ok”就是没有问题)
./nginx -t
# 停止nginx
./nginx -s stop
# 重启nginx
./nginx -s reload
8、测试nginx是否正常启动
curl http://localhost
# 当出现如下文本及为成功
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>