ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

nginx编译安装

2021-10-26 19:01:30  阅读:97  来源: 互联网

标签:http log Nginx 安装 nginx 编译 local usr


一、Nginx是什么?


Nginx是web服务软件。

Nginx是一个开源且高性能、可靠的http web服务、代理服务的软件

1、开源
2、Nginx web服务器
3、Nginx是俄罗斯一个程序员
4、Nginx还是代理

 

二、Nginx和Apache之间对比

网络模型:
select 性能最低
poll 性能稍好
epoll 性能最强

Apache : select
Nginx : epoll

 

三、安装Nginx

wget http://nginx.org/download/nginx-1.20.1.tar.gz
tar -xf nginx-1.20.1.tar.gz
cd nginx-1.20.1
./configure --with-http_ssl_module --with-http_v2_module --with-stream --prefix=/usr/local/nginx
make && make install
echo "export PATH=$PATH:/usr/local/nginx/sbin" >> /etc/profile #设置环境变量
source /etc/profile

root@web03 sbin]# vi /usr/lib/systemd/system/nginx.service                                         #加入system管理
[Unit] 
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop

[Install]
WantedBy=multi-user.target

 

systemctl daemon-reload
systemctl start nginx

  

 

四、nginx常用命令

nginx -v : 展示nginx的版本号
nginx -V :展示nginx版本号和配置参数
nginx -t : 测试配置文件
nginx -T : 测试配置文件并打印
nginx -q : 静默输出错误信息
nginx -s : 向nginx发送信号
nginx -p : 指定运行的家目录
nginx -e : 设置错误日志的路径
nginx -c : 设置配置文件
nginx -g : 临时设置配置项

 

五、nginx配置文件详解

	
# 工作进程启动用户
user  nginx;
# 启动的worker进程数
worker_processes  auto;
# 指定错误日志的路径
error_log  /var/log/nginx/error.log notice;
# 指定nginx进程的PID
pid        /var/run/nginx.pid;
# 配置事件
events {
    # worker进程中最大的连接数
    worker_connections  1024;
}

# http配置模块
http {
	# include 是讲其他文件导入进来
    include       /etc/nginx/mime.types;
	
	# default_type 指定nginx处理文件的默认类型
    default_type  application/octet-stream;

	# 定义日志的格式
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
	
	# 定义日志路径
    access_log  /var/log/nginx/access.log  main;

	# 高效读取文件
    sendfile        on;
    #tcp_nopush     on;
	
	# 长连接的超时时间
	keepalive_timeout  65;

	# 设置GZIP压缩
    #gzip  on;

	# 加载其他的配置文件
    include /etc/nginx/conf.d/*.conf;
}

game.conf 
# 每一个server都代表一个网站(nginx是支持多个网站)
server {
	# 指定当前网站的域名
	server_name www.baidu.com;
	
	# 指定当前网站的端口
	listen 80;
	
	# 指定一个访问路径
	location / {
		
		# 指定站点目录
		root /opt/html;
		# 指定默认访问的文件
		index index.html;
	}
}

  

 

nginx和Apache性能对比

https://www.cnblogs.com/RRecal/p/15467229.html 

 

标签:http,log,Nginx,安装,nginx,编译,local,usr
来源: https://www.cnblogs.com/RRecal/p/15467294.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有