没有合适的资源?快使用搜索试试~ 我知道了~
服务器 Nginx是一个高性能的HTTP服务器和反向代理,它以高稳定性、丰富的功能集、简单的配置和低资源消耗而闻名。以下是Nginx服务器配置的基本步骤: 安装Nginx: 在Linux系统上,可以使用包管理器安装Nginx,如在Ubuntu上使用命令sudo apt-get install nginx。 基本配置: Nginx的配置文件通常位于/etc/nginx/nginx.conf。 配置文件结构: Nginx配置文件采用层级结构,包括main、events、http块,以及在http块内的server块。 设置worker进程: 在events块中,可以设置worker进程的数量,通常设置为CPU核心数。 配置HTTP服务器: 在http块中,可以配置文件扩展名与文件类型、日志路径、连接超时时间等。 配置虚拟主机: 在http块内,使用server块来配置虚拟主机。每个server块都包含一个监听端口(通常是80或443)和一个server_name。 配置网站根目录: 使用root指令指定网站的根目录,例如root /var/www/html;。
资源推荐
资源详情
资源评论
0x00 编译实践
描述:在企业线上生产环境中推荐进行 Nginx 编译安装,可以按照业务侧重点进行相
应 Nginx 编译参数配置,所以编译参数不是功能加的越多越好,应该尽可能少编
译模块不用的最好不要加入,本小结将以最新的 Nginx 版本以及依赖版本进行编译
演示。
Nginx-1.21.6+OpenSSL-1.1.1n
最新源码构建安装整理,当前最新版本 nginx-1.21.6,实践时间【2022 年 3 月 24
日】
版本说明: pcre-8.45 、zlib-1.2.11、openssl-1.1.1n、nginx-1.21.6。
官方安装参考地址: https://docs.nginx.com/nginx/admin-guide/installing-
nginx/installing-nginx-open-source/#downloading-the-sources
步骤 01.在从源代码编译 NGINX Open Source 之前,您需要为其依赖项安装库:
� PCRE – 支持正则表达式,NGINX Core 和 Rewrite 模块需要。
# http://pcre.org/
# https://sourceforge.net/projects/pcre/files/
wget -c https://nchc.dl.sourceforge.net/project/pcre/pcre/8.45/pcre-
8.45.tar.bz2
tar -jxf pcre-8.45.tar.bz2 && cd pcre-8.45
./configure
make && sudo make install
� zlib – 支持标头压缩, NGINX Gzip 模块需要。
# http://www.zlib.net/
wget -c http://zlib.net/zlib-1.2.11.tar.gz
tar -zxf zlib-1.2.11.tar.gz && cd zlib-1.2.11
./configure
make && sudo make install
� OpenSSL – 支持 HTTPS 协议, NGINX SSL 模块和其他模块需要。
# https://www.openssl.org/source/
wget -c http://www.openssl.org/source/openssl-1.1.1n.tar.gz
tar -zxf openssl-1.1.1n.tar.gz && cd openssl-1.1.1n
./config --prefix=/usr/local/openssl
make && sudo make install
# lib 库加载到系统
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf.d/libc.conf
ldconfig
# 可以看到当下系统的 Openssl 版本已经更新到最新
# root@weiyigeek-top:/usr/local/openssl/bin# openssl version
# OpenSSL 1.1.1n 15 Mar 2022
步骤 02.从 nginx.org 下载稳定版和主线版本的源代码文件,要下载并解压最新主
线版本的源代码,请运行:
# https://nginx.org
sudo mkdir -vp /usr/local/nginx/module /usr/lib/nginx/modules
/var/cache/nginx/{client_temp,proxy_temp,fastcgi_temp,uwsgi_temp,scgi_temp
}
wget https://nginx.org/download/nginx-1.21.6.tar.gz
tar zxf nginx-1.21.6.tar.gz && cd nginx-1.21.6
$ ./configure \
--prefix=/usr/local/nginx \
--with-pcre=../pcre-8.45 \
--with-zlib=../zlib-1.2.11 \
--user=ubuntu --group=ubuntu \
--sbin-path=/usr/sbin/nginx \
--conf-path=/usr/local/nginx/nginx.conf \
--pid-path=/usr/local/nginx/nginx.pid \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--lock-path=/var/run/nginx.lock \
--modules-path=/usr/lib/nginx/modules \
--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-stream --with-stream_realip_module --with-stream_ssl_module --with-
stream_ssl_preread_module --with-stream_geoip_module \
--with-threads --with-mail --with-mail_ssl_module \
--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 --with-
http_stub_status_module --with-http_sub_module --with-http_v2_module \
--with-compat --with-file-aio \
--with-cc-opt= '-Os -fomit-frame-pointer -g' --with-ld-opt=-Wl,--as-
needed,-O1,--sort-common
# <!-- --add-dynamic-module=/usr/local/nginx/module -->
Tips :请注意 geoip_module 模块, 如果需要使用则需要提前安装好 GeoIP
library,例如在 Ubuntu 系统上执行 apt-get install libgeoip-dev 如下命令。
Tips : 请注意 通过 yum 或者 apt 安装的 nginx,通常会将 nginx 的配置文件放在
/etc/nginx,而手动编译构建的一般是在 /usr/local/nginx 目录中。
步骤 03.执行./configure 命令后的结果如下
Configuration summary
+ using threads
+ using PCRE library: ../pcre-8.45
+ using system OpenSSL library
+ using zlib library: ../zlib-1.2.11
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/sbin/nginx"
nginx modules path: "/usr/lib/nginx/modules"
nginx configuration prefix: "/usr/local/nginx"
nginx configuration file: "/usr/local/nginx/nginx.conf"
剩余66页未读,继续阅读
资源评论
技术分享官
- 粉丝: 1742
- 资源: 185
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功