Nginx 部署文档
off999 2025-01-12 17:40 18 浏览 0 评论
一、文档介绍
此文档旨在规范服务器上 Nginx 部署步骤,标准化操作步骤,为后续标准运维提供支撑。
二、部署说明
- 操作系统:Linux(CentOS 7.6)
- 安装包版本:Nginx 1.26.2
三、下载
官网下载地址:https://nginx.org/download/
cd /usr/local/src
wget https://nginx.org/download/nginx-1.26.2.tar.gz四、安装依赖包
yum install -y openssl openssl-devel pcre pcre-devel libxml2 libxml2-devel libxslt libxslt-devel gd gd-devel pcre pcre-devel perl-ExtUtils-Embed五、安装
cd /usr/local/src
tar zxf nginx-1.26.2.tar.gz
cd nginx-1.26.2
# 解决无法找到 openssl 问题
sed '/ngx_feature_libs/s#R/usr/local/lib #R/usr/local/lib64 #g' auto/lib/openssl/conf
# 编译
./configure --prefix=/usr/local/nginx --with-compat --with-debug --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_degradation_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_perl_module=dynamic --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-http_mp4_module --with-http_xslt_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module --with-threads
make -j2
# 安装
make install六、创建目录
mkdir -p /data/nginx_data/
mkdir -p /data/logs/nginx
cd /usr/local/nginx
mv conf /data/nginx_data/
ln -s /data/nginx_data/conf conf
mkdir -p conf/conf.d
rm -rf logs
ln -s /data/logs/nginx logs
mkdir -p /data/nginx_data/certs
ln -s /data/nginx_data/certs certs七、配置环境变量
cat <<"EOF" | tee -a /etc/profile
# nginx
export NGINX_HOME=/usr/local/nginx
export PATH=$NGINX_HOME/sbin:$PATH
EOF
source /etc/profile八、修改配置文件
cd /usr/local/nginx/conf
cat <<EOF | tee nginx.conf
user root ;
worker_processes auto;
worker_cpu_affinity auto;
events {
use epoll;
worker_connections 65535;
accept_mutex on;
multi_accept on;
}
http {
include mime.types;
default_type application/octet-stream;
underscores_in_headers on;
server_tokens off;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" $request_time '
'$upstream_response_time $upstream_addr $upstream_status';
access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
proxy_buffer_size 128k;
proxy_buffers 32 32k;
proxy_busy_buffers_size 128k;
keepalive_timeout 65;
gzip on;
gzip_proxied any;
#gzip_min_length 1k;
gzip_comp_level 6;
#gzip_buffers 4 32k;
gzip_http_version 1.1;
gzip_types text/plain text/css text/xml text/javascript application/xml application/javascript application/json application/octet-stream image/jpeg image/gif image/png;
include conf.d/*.conf;
}
EOF九、创建服务
cd /data/nginx_data
cat <<EOF | tee nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
# Nginx will fail to start if /run/nginx.pid already exists but has the wrong
# SELinux context. This might happen when running `nginx -t` from the cmdline.
# https://bugzilla.redhat.com/show_bug.cgi?id=1268621
ExecStartPre=/usr/bin/rm -f /run/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload -c /usr/local/nginx/conf/nginx.conf
ExecStop=/usr/local/nginx/sbin/nginx -s stop -c /usr/local/nginx/conf/nginx.conf
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
cp nginx.service /usr/lib/systemd/system/十、启动服务
systemctl daemon-reload
systemctl enable nginx --now
systemctl status nginx十一、添加配置
代理或前端配置文件目录:/usr/local/nginx/conf/conf.d。例如:
(一) 前端
server {
listen 80;
location / {
alias /usr/share/nginx/html/dist/;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
}(二) HTTP 代理
server {
listen 443 ssl;
listen 80;
server_name api.rucjohn.tech;
index index.html index.htm index.php;
ssl_prefer_server_ciphers on;
ssl_protocols TLSv1 TLSv1.1 TLSV1.2;
ssl_ciphers AES128-SHA:AES256-SHA:RC4-SHA:DES-CBC3-SHA:RC4-MD5;
ssl_certificate "/usr/local/nginx/certs/server.crt";
ssl_certificate_key "/usr/local/nginx/certs/server.key";
location ^~ /api/v1/simple {
proxy_pass http://127.0.0.243;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}(三) TCP 代理
upstream mysql {
hash $remote_addr consistent;
server 127.0.0.240:3306;
}
server {
listen 13306 so_keepalive=on;
proxy_pass mysql;
}相关推荐
- win8家庭中文版下载(windows家庭中文版下载)
-
可以按照以下步骤在Win8上下载和安装Word:1.通过微软官网下载购买,或者通过MicrosoftStore应用商店进行购买和下载。2.下载完成后,打开文件夹,双击setup进行安装。3.安...
- 教大家强制退出苹果id账号(教大家强制退出苹果id账号ipad)
-
1.首先将手机强制关机,并在电脑端安装iTunes并打开。2.用数据线将手机与电脑连接起来,长按手机电源键。3.当出现苹果标志时不要松开电源键,接着按Home键。4.直到屏幕黑屏,松开电源键。5.继续...
- 惠普官网驱动下载官网(惠普驱动官方)
-
在惠普官网下载系统驱动方法如下访问HP官网:www.hp.com找到支持与驱动页面(通常在顶部导航栏的支持或下载中)输入你的HP产品的序列号或选择产品类型和型号选择你的操作系统,然后下载相关的驱动。安...
- 电脑公司取名字大全(电脑行业公司取名)
-
动感网络IT狂人行鱼雷IT网PC宝宝网外有鱼超导技术网PC技术网加点分吧,不然想不出太多,呵呵绿苑计算机协会绿色代表生命,有起航的意义,苑是一个范畴,有地域的意思,是给你们一片天地的意思...
- wifi怎么设置网速快(手机测wifi网速怎么测)
-
wifi加速设置方法步骤如下。1设置网速:浏览器中输入终端地址,输入账号和密码。找到连接设备数目并进行更改,找到信道宽度,选择更快的网速。2提高WiFi网速:进入设置中心,点击WLAN选项。点击高级设...
- 华硕驱动软件叫什么(华硕自带驱动管理软件)
-
q-installer驱动啥意思?华硕q-installer驱动能让用户更加方便地管理各种文件。将会同时显示4个Windows资源管理器的窗口,这样能让用户更加简单地对文件进行一些操作,例如复制,粘贴...
- 懂行的人建议买华为还是惠普电脑
-
华为电脑好。华为笔记本电脑主打的就是轻薄,质感,多屏协同生态,面向商务人群和学生党。目前在售的机型并不多,但每一台机子本身都不错,不过因为被制裁的缘故,定价过高,性价比打折扣。惠普笔记本好,惠普除了家...
- 如何把win系统换成安卓(怎么把系统改为win10)
-
方法/步骤分步:1首先点击打开酷安应用市场;2点击打开位于屏幕右下方的“应用游戏”选项;3选择想要下载的软件或者游戏app,点击进入;4选择“下载”按钮,点击开始下载;5APP下载完成后,系统会自动跳...
-
- 如何复制粘贴(如何复制粘贴excel表格内容)
-
需要复制文字的时候只要先选中文字,然后同时按住Ctrl+C键,然后松手就已经复制了文字,在需要粘贴的地方同时按住:Ctrl+V就可以看到文字被粘贴了,非常的方便。扩展资料:Alt键,这个键叫做改变,很多快捷键都需要使用到这个键,矩形...
-
2025-11-14 05:51 off999
- hotmail电子邮箱登录(hotmail邮箱在线登录)
-
***@hotmail.com1、其中***是你自己申请的邮箱的用户名。2、hotmail要写在符号@后面。3、最后加上.com,这样就是一个完整的hotmail邮箱的格式。4、比如:zhangj...
- win10iso文件(win10iso文件怎么安装)
-
安装Win10ISO系统文件需要以下步骤:1.首先需要从Microsoft官网下载Win10ISO系统文件,打开网站后选择Win10的版本、语言和架构(32位或64位),点击下载即可。2.下载...
欢迎 你 发表评论:
- 一周热门
-
-
抖音上好看的小姐姐,Python给你都下载了
-
全网最简单易懂!495页Python漫画教程,高清PDF版免费下载
-
Python 3.14 的 UUIDv6/v7/v8 上新,别再用 uuid4 () 啦!
-
python入门到脱坑 输入与输出—str()函数
-
飞牛NAS部署TVGate Docker项目,实现内网一键转发、代理、jx
-
宝塔面板如何添加免费waf防火墙?(宝塔面板开启https)
-
Python三目运算基础与进阶_python三目运算符判断三个变量
-
(新版)Python 分布式爬虫与 JS 逆向进阶实战吾爱分享
-
慕ke 前端工程师2024「完整」
-
失业程序员复习python笔记——条件与循环
-
- 最近发表
- 标签列表
-
- python计时 (73)
- python安装路径 (56)
- python类型转换 (93)
- python进度条 (67)
- python吧 (67)
- python的for循环 (65)
- python格式化字符串 (61)
- python静态方法 (57)
- python列表切片 (59)
- python面向对象编程 (60)
- python 代码加密 (65)
- python串口编程 (77)
- python封装 (57)
- python写入txt (66)
- python读取文件夹下所有文件 (59)
- python操作mysql数据库 (66)
- python获取列表的长度 (64)
- python接口 (63)
- python调用函数 (57)
- python多态 (60)
- python匿名函数 (59)
- python打印九九乘法表 (65)
- python赋值 (62)
- python异常 (69)
- python元祖 (57)
