Linux下安装Nginx

作者:Grey

原文地址:Linux下安装Nginx

版本

Nginx:1.21.6

操作系统:CentOS 7/Debian 11

安装必要工具和依赖

yum -y install wget gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel

注:如果是Debian系,安装的包名会有差别

apt-get install libpcre3 libpcre3-dev openssl libssl-dev

下载源码包

cd /usr/local/src
wget http://nginx.org/download/nginx-1.20.1.tar.gz

解压

tar xf nginx-1.20.1.tar.gz

重命名

mv nginx-1.20.1 nginx

configure

cd /usr/local/src/nginx

## 后面两个module是支持https必要的
./configure  --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

执行完毕后,会显示类似如下的信息,表示成功

Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + using system zlib library

  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

cd /usr/local/src/nginx
make

make install

cd /usr/local/src/nginx
make install

开启nginx默认的80端口的访问权限

firewall-cmd --zone=public --add-port=80/tcp --permanent  
firewall-cmd --reload 

注:如果是Debian类系统,需要执行如下命令

apt-get install iptables
# 例如要放行8881端口
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
# 然后保存放行规则
iptables-save
# 设置完就已经放行了指定的端口,但重启后会失效,下面设置持续生效规则;
# 安装iptables-persistent
apt-get install iptables-persistent -y
# 保存规则持续生效
netfilter-persistent save
netfilter-persistent reload

指定nginx配置文件启动方式

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

验证,访问: http://yourip

可以看到如下欢迎页面,表示安装成功。

Linux下安装Nginx_第1张图片

你可能感兴趣的:(Linux,运维,Linux,Nginx,CentOS,Debian)