当前位置:首页 > 技术文章 > 正文内容

Linux 系统安装 Nginx

arlanguage5个月前 (12-13)技术文章36

Linux 系统安装 Nginx

CentOS 7 Nginx 源代码编译安装

# 官网下载最新版
https://nginx.org/en/download.html

# 系统安装必备组件:
yum install gcc gcc-c++ pcre pcre-devel zlib-devel openssl-devel openssl -y

# 添加Nginx用户:
useradd nginx -s /sbin/nologin -M

# 建立对应目录:
mkdir -p /var/cache/nginx/client_temp
yum -y install unzip

# 源码解压缩配置:
确保 nginx-rtmp-module-master.zip 和 nginx-1.22.1.tar.gz 在同一目录下
unzip nginx-rtmp-module-master.zip 
tar -xf nginx-1.22.1.tar.gz
cd nginx-1.22.1
./configure --user=nginx --group=nginx --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp  --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --add-module=../nginx-rtmp-module-master --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'

# 快速测试上一步运行是否出错(正确数字为0,错误为其他数字):
echo $?
0
# 编译安装
make && make install

# 快速测试上一步运行是否出错(正确数字为0,错误为其他数字):
echo $?
0

# 查看Nginx版本及安装参数:
nginx -V

Ubuntu 安装 Nginx

# 系统软件源安装
apt install nginx -y

# 开机启动
systemctl enable nginx

# 关闭服务
systemctl stop nginx

# 启动服务
systemctl start nginx

# 查看服务状态
systemctl status nginx

# 重启服务
systemctl restart nginx

# 创建日志目录及文件
mkdir -p /usr/share/nginx/logs/
touch /usr/share/nginx/logs/error.log

# 保存原始配置文件
mv /etc/nginx/nginx.conf /etc/nginx/nginx.confori

# 过滤注释行
grep -Ev '^$|#' /etc/nginx/nginx.conf

Docker 运行 Nginx

# 拉取镜像
docker pull nginx

# 创建目录及修改权限
mkdir -p /root/nginx_conf/conf.d
mkdir /root/nginx_logs
mkdir /root/nginx_web
chmod -R 777 /root/nginx_conf
chmod -R 777 /root/nginx_logs
chmod -R 777 /root/nginx_web

# 启动 Nginx
docker run -itd --name nginx -p 80:80 -p 443:443 -v /root/nginx_web:/var/www/html -v /root/nginx_conf:/etc/nginx -v /root/nginx_logs:/var/log/nginx nginx



扫描二维码推送至手机访问。

版权声明:本文由AR编程网发布,如需转载请注明出处。

本文链接:http://www.arlanguage.com/post/126.html

分享给朋友:

“Linux 系统安装 Nginx” 的相关文章

修改配置nginx限制无良爬虫频率

我们公司某些服务也经常被爬虫影响,例如贴吧在贴吧这个事故中,我是简单地匹配useragent,给它返回一个500的错误。今天看微博发现@金荣叶 的处理方法很灵活,可以动态设定一个爬虫的频率,达到减轻服务器负载,并且不至于封杀爬虫。#全局配置limit_req_zone $anti_spider zo...

2022年从零开始,用一篇博客掌握 nginx 的初级配置

当 nginx 安装之后,默认的配置如下所示(数据来源为宝塔自动生成),本篇博客重点介绍的是配置虚拟机相关内容,即 server 块配置项。 server 块的指令主要用于设置主机和端口, location 块用于匹配网页路径,一个 http 块可以包含多个 server 。基础配置server {...

利用Nginx反向代理,不重新解析域名对网站进行服务器迁移

因为项目需要,现在想将A服务器上的网站(代码)转移到B服务器上,但是不想重新做域名解析,因为这段时间网站收录方面都比较优秀,冒然修改解析怕对网站收录有影响。所以借助一下Nginx的反向代理,将域名从A服务器反向代理到B服务器。首先将B服务器的环境做成和A一致(Nginx+PHP7.2+Mysql)。...

haproxy负载均衡入门到转行

haproxy概述haproxy是一款开源的高性能的反向代理或者说是负载均衡服务软件之一,支持双机热备,虚拟主机基于TCP/HTTP应用代理,具有图形界面等功能。其配置简单,而且拥有很好的对服务器节点的健康检查功能(相当于keepalived健康检查),当其代理的后端服务器出现故障时,haproxy...

一文说清nginx规则匹配(含案例分析)

概述: 在nginx中,匹配分很多情形,例如:区分大小写匹配、不区分大小写匹配、有强匹配开头、有模糊匹配某些字符、有匹配后重写动作、有匹配反向代理动作、有匹配后终止操作、还有匹配全局变量类型等等,在很多情形中,匹配动作也存在优先策略,来看看下面的案例。案例一、 server { .............

Linux系统非root用户下安装Nginx

通常使用Nginx或者Apache作为Web服务器时,默认监听80端口,因此默认会使用root用户去安装,而且,使用yum命令安装时,通常会安装到默认的路径下,默认路径通常是root用户才有执行权限的。如果不需要使用Nginx监听1024以下的端口,且对权限和网络管理比较严格时,能用非root权限解...