百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 技术资源 > 正文

Nginx 部署文档

off999 2025-01-12 17:40 27 浏览 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;
}

相关推荐

手机版爱思助手app下载苹果版

第一步:我们先在电脑上安装好爱思助手,并且把手机与电脑连接起来;  第二步:在电脑上打开爱思助手以后,点击顶部的“软件资源”栏目;  第三步:随后在软件资源列表中即可看到“爱思助手”应用,点击...

ie浏览器图标删除不了(ie浏览器从桌面无法删除)

  方法一:  1、点击“开始”,在搜索中输入“gpedit.msc”回车打开注册表;  2、点击“用户配置-管理模板-桌面”左侧的下拉按钮;  3、单击”桌面“,右侧弹出桌面的设置栏;  4、双击“...

bitlocker是什么意思(bitlocker属于什么锁)

Bitlocker的意思:驱动器加密;磁盘加密;硬盘加密。BitLocker驱动器加密它是在WindowsVista中新增的一种数据保护功能,主要用于解决一个人们越来越关心的问题:由计算机设备的物理...

win10开机启动文件夹在哪里(电脑开机启动文件夹win10)

win7下:在运行里打入gpedit.msc然后回车。用户配置-〉管理模板-〉系统点击右边“只运行指定的windows程序”点击允许的应用程序列表显示按钮在里面添加需要运行的程序,...

如何升级win11专业版(升级win11专业版会删掉东西吗)

简单来说,目前升级到Windows11系统上,有三种常见方法:1、通过微软推送更新,从Windows更新升级。2、更新不求人,通过Win11更新助手升级。助手更新系统也非常简单省心。3、无视硬件限制...

office2007支持win10吗(office2007支持win7吗)

1不兼容2Office2007和Windows10之间存在一些兼容性问题。Office2007是较旧的版本,而Windows10是较新的操作系统。因此,某些功能可能无法在Office20...

rar解压软件pc版(pc端rar解压软件)
  • rar解压软件pc版(pc端rar解压软件)
  • rar解压软件pc版(pc端rar解压软件)
  • rar解压软件pc版(pc端rar解压软件)
  • rar解压软件pc版(pc端rar解压软件)
解压软件rar下载(解压软件rar下载什么)
解压软件rar下载(解压软件rar下载什么)

rar是一种文件压缩格式,可以把一个文件压缩到只有原来文件的几分之一大小。大大节省了存储空间。rar文件怎么打开呢,需要电脑上安装文件压缩软件,解压才能打开压缩包里的文件。WinRAR软件是用的最多的压缩软件,一般电脑装系统时都装了这个软件...

2026-01-12 04:51 off999

戴尔电脑官方售后服务网点(戴尔电脑官方售后地点)

戴尔笔记本电脑维修点有4个,地点如下:A:戴尔笔记本电脑维修点地址:上海市长宁区长宁路1027号兆丰广场5层B:戴尔笔记本电脑维修点地址:上海市徐汇区漕溪北路45号C:戴尔笔记本电脑维修点地址:上...

电脑哪个键是截图(苹果电脑哪个键是截图)

1.第一个,通过键盘上的截图键来截取全屏,键盘上都有一个printscreen键,这个键就是用来截图的,只需要按一下这个键,然后再打开word文档,然后按一下ctrl+v键,就可以把这个截图,粘贴...

下载设置到手机上(手机设置下载到桌面上)
下载设置到手机上(手机设置下载到桌面上)

1.打开手机的“设置”图标。2.进入设置页面,滑动手机屏幕,找到“桌面、锁屏与息屏”选项并点击。3.进入新页面,滑动手机屏幕找到“添加应用到主屏幕”选项,此时该选项右侧的按钮为关闭状态。4.点击一下“添加应用到主屏幕”选项右侧的按钮,按钮点...

2026-01-12 03:03 off999

怎样安装打印机驱动到电脑的步骤
  • 怎样安装打印机驱动到电脑的步骤
  • 怎样安装打印机驱动到电脑的步骤
  • 怎样安装打印机驱动到电脑的步骤
  • 怎样安装打印机驱动到电脑的步骤
如何连接打印机网络共享(打印机如何通过网络共享)

打印机设置共享打印的操作步骤一、在连接打印机的电脑上依次点击“开始“菜单-”设置“-”打印机“,打开打印机界面后右键单击“打印机”图标点击到“共享”选项界面接着点击“共享这台打印机”,最后点击“确定”...

win10自带风扇控制软件(w10风扇管理在哪里)

在Windows10系统中,风扇的设置通常是由计算机硬件和BIOS控制的。但是,您也可以使用一些软件工具来调整风扇的设置。以下是一些常用的方法:1.使用BIOS设置:在计算机启动时按下相应的按键(...

系统类小说女主文(系统文推荐女主)

1、《团宠郡主有系统》2、《绑定才女系统后文躺赢了》 3、《炮灰女配苟成了女主》 4、《在暴君身边卑微求生》 5、《师徒恋文里的反派非要和我HE》6、《穿成反派男主极品娘...

取消回复欢迎 发表评论: