首页 > 系统相关 >Nginx部署安装

Nginx部署安装

时间:2024-04-17 14:11:52浏览次数:24  
标签:1.16 http nginx 部署 安装 Nginx usr -- local

 

#部署前准备工作

#配置阿里云的yum源
yum -y install wget

cd /etc/yum.repos.d/ wget http://mirrors.aliyun.com/repo/Centos-7.repo mv CentOS-Base.repo CentOS-Base.repo.bak mv Centos-7.repo CentOS-Base.repo yum clean all yum makecache yum update

 

yum -y install wget vim lrzsz make cmake gcc gcc-c++

yum install -y libtool pcre pcre-devel zlib zlib-devel openssl openssl-devel perl-ExtUtils-Embed

useradd nginx -s /sbin/nologin -M

#下载安装包、部署服务

cd /usr/local/src/

wget https://nginx.org/download/nginx-1.16.1.tar.gz

tar zxvf nginx-1.16.1.tar.gz

cd nginx-1.16.1/

./configure --prefix=/usr/local/nginx-1.16.1 --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module

make && make install

ln -s /usr/local/nginx-1.16.1/ /usr/local/nginx

chown -R nginx.nginx /usr/local/nginx-1.16.1

#常用模块参数
./configure --prefix=/usr/local/nginx-1.24.0/ \ --user=nginx \ --group=nginx \ --with-http_ssl_module \ --with-http_v2_module \ --with-http_realip_module \ --with-http_stub_status_module \ --with-http_gzip_static_module \ --with-pcre \ --with-stream \ --with-stream_ssl_module \ --with-stream_realip_module
Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + using system zlib library

  nginx path prefix: "/usr/local/nginx-1.16.1"
  nginx binary file: "/usr/local/nginx-1.16.1/sbin/nginx"
  nginx modules path: "/usr/local/nginx-1.16.1/modules"
  nginx configuration prefix: "/usr/local/nginx-1.16.1/conf"
  nginx configuration file: "/usr/local/nginx-1.16.1/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx-1.16.1/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx-1.16.1/logs/error.log"
  nginx http access log file: "/usr/local/nginx-1.16.1/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"

#启动服务

/usr/local/nginx/sbin/nginx

[root@localhost conf]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      4087/nginx: master  

#优化配置文件

#原配置文件
user nginx; worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }

 #优化Nginx服务的worker进程个数

#查看服务cpu核数
grep 'processor' /proc/cpuinfo |wc -l 2
#修改nginx.con中的worker_processes worker_processes 2;
#修改前默认一个master一个worker process; [root@localhost conf]# ps aux | grep nginx root 4087 0.0 0.1 46056 1932 ? Ss Apr15 0:00 nginx: master process /usr/local/nginx/sbin/nginx nginx 42506 0.0 0.2 46496 2028 ? S 01:05 0:00 nginx: worker process #检查配置文件、重载配置文件 [root@localhost conf]# /usr/local/nginx/sbin/nginx -t nginx: the configuration file /usr/local/nginx-1.16.1/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx-1.16.1/conf/nginx.conf test is successful [root@localhost conf]# /usr/local/nginx/sbin/nginx -s reload #worker process数量已经变为两个 [root@localhost conf]# ps aux | grep nginx | grep -v "grep" root 4087 0.0 0.1 45960 1972 ? Ss Apr15 0:00 nginx: master process /usr/local/nginx/sbin/nginx nginx 42582 0.0 0.1 46396 1940 ? S 01:31 0:00 nginx: worker process nginx 42583 0.0 0.1 46396 1940 ? S 01:31 0:00 nginx: worker process

#配置Nginx worker进程最大打开文件数

#如果系统没优化过默认很低(我的是1024)
[root@localhost conf]# ulimit -n 1024
[root@localhost ~]# vim /etc/security/limits.conf # End of file
root soft nofile 65535
root hard nofile 65535
* soft nofile 65535
* hard nofile 65535
#重新登录或重启系统后查看
[root@localhost ~]# ulimit -n
65535
#接下来修改nginx配置文件,在核心配置区中加入以下配置,保存后重载nginx
worker_rlimit_nofile 65535;

 #调整Nginx单个进程允许的客户端最大连接数(在核心配置区中加入以下配置,保存后重载nginx)

 worker_connections  20480;

#根据系统的最大打开文件数来调整,worker_connections进程连接数量要小于等于系统的最大打开文件数

 #隐藏版本号(在http标签中加入以下配置并重载配置文件)

server_tokens off;

#关闭前
[root@localhost conf]# curl -I 127.0.0.1
HTTP/1.1 200 OK
Server: nginx1.16
Date: Thu, 16 Apr 2020 02:57:50 GMT
Content-Type: text/html
#关闭后
[root@localhost conf]# curl -I 127.0.0.1
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 16 Apr 2020 03:13:55 GMT
Content-Type: text/html

 #设置nginx连接超时时间(在http标签中加入以下配置并重载配置文件)

keepalive_timeout  60;

标签:1.16,http,nginx,部署,安装,Nginx,usr,--,local
From: https://www.cnblogs.com/sparkss/p/12705124.html

相关文章

  • 【笔记】RedmiBookPro15锐龙板(7840hs)安装ubuntu2204注意事项
    /** 2024-04-17 12:53:52*/1、不要安装ubuntu2004,驱动问题很烦入,尤其是AMD的显卡驱动,不论哪个版本都不要打AMD的官方驱动,经常花屏,卡的完全不能操作,自带的开源驱动就行了,偶尔出现一两道花屏的,不影响使用,而且一会就消失了。如果经常出现在bios里调大显存试试,默认512估计不够,我......
  • step by step系列之:openGauss1.0.1单机安装指南v1.2
    StepbyStep之:openGauss1.0.1单机安装指南v1.2在CentOS7.6上安装openGauss单机版配置操作系统满足安装要求硬件环境:虚拟机的内存8GB,4核心CPU,900G磁盘(非必须)软件环境:CentOS7.6关闭防火墙停止firewallsystemctlstopfirewalld.service禁止firewall开机启动......
  • C:\Windows\System32\setup 目录中,这个目录包含了一些与系统安装和配置相关的文件
    C:\Windows\System32\setup目录中,这个目录包含了一些与系统安装和配置相关的文件。作用:cmmigr.dll:这是一个动态链接库文件,可能与移动设备中心相关。它可能包含了用于迁移和处理移动设备中心配置的函数和资源。comsetup.dll:这是ComponentServicesSetup工具的......
  • 解决.Net6 部署到ubuntu22.04中使用DotNetCore.NPOI 导出报 Could not open display (
    在Ubuntu22环境下,出现"Couldnotopendisplay(X-Serverrequired.CheckyourDISPLAYenvironmentvariable)"错误可能是由于缺少X服务器或未正确配置DISPLAY环境变量导致的。以下是你可以尝试的解决方法:检查DISPLAY环境变量:确保DISPLAY环境变量已正确设置。使......
  • SQL Server安装以及使用Navicat连接遇到的问题的解决方式
    1、SQLServer安装,参考连接:SQLServer2019安装详细教程(图文详解,非常靠谱)2、远程服务器:Navicat连接报错:TCP提供程序:由于目标计算机积极拒绝,无法连接.该错误有2个方面的问题需要解决(1)远程服务器是否能够telnet服务器的ip和端口, 解决方式:在SQLServer服务器的防火墙中增......
  • openGauss在kubernetes集群环境上的部署
    opengauss实践总结学习心openGauss是一款开源关系型数据库管理系统,深度融合华为在数据库领域多年的经验,结合企业级场景需求,持续构建竞争力特性;kubernetes也是一个开源的,用于管理云平台中多个主机上的容器化的应用,Kubernetes的目标是让部署容器化的应用简单并且高效,Kuber......
  • Go--goland下载安装
    下载地址:https://www.jetbrains.com/go/download/other.html 然后进行安装,将可选那一步全勾选 运行程序好,要设置激活码或者选择登陆账户,不然不可用,激活码可以网上找免费的  新建项目 将语言设置成中文,下载chinses插件,重新运行 ......
  • Linux centos安装tesseract-ocr教程
    安装依赖依赖的包:autoconfautomakelibtoollibjpeg-devellibpng-devellibtiff-develzlib-develleptonica(1.67以上)(一下环境依赖,有则更新,无则安装)yuminstallautoconfautomakelibtoolyuminstalllibjpeg-devellibpng-devellibtiff-develzlib-develLeptonica库......
  • web server apache tomcat11-03-deploy 如何部署
    前言整理这个官方翻译的系列,原因是网上大部分的tomcat版本比较旧,此版本为v11最新的版本。开源项目从零手写实现tomcatminicat别称【嗅虎】心有猛虎,轻嗅蔷薇。系列文章webserverapachetomcat11-01-官方文档入门介绍webserverapachetomcat11-02-setup启动web......
  • 安装软件提示 Runtime Error (at 28:321): Generic faiure Swbemlocator
    第一次遇见这个问题,查了下,根据ai智能提示总结下。报错解释:这个错误通常表示在Windows操作系统中,在安装或运行软件时,与WindowsManagementInstrumentation(WMI)服务交互时出现问题。SwbemLocator是一个COM对象,用于连接到WMI服务,进行系统管理任务。"Genericfailure"意味着操作......