Nginx based applications, build a website

A, nginx basic introduction

1.1: What is Nginx

Nginx is an open source, high-performance, reliable Http Web services, agency services.
Open source, reflected in the direct access to the source code Nginx
performance, reflected in the concurrent support large numbers
of high reliability, stability is reflected in the service

1.2: Why Nginx

  • High-performance, high concurrency
  • High scalability
  • High reliability
  • Hot deployment
  • Nginx network model using Epool
  • Second, using Nginx unified technology stack, reducing maintenance Castle, while reducing technology updates castle

1.3: Nginx What usage scenarios

Nginx main usage scenario I summarized into three, namely static resource services, agency resources services, security services.

		1、nginx web服务
		2、nginx反向代理
		3、nginx反向代理-->负载均衡
		4、nginx反向代理-->缓存 
		5、nginx静态加速
		6、nginx动静分离
		7、nginx全栈https

Two, Nginx installation and deployment

1、配置Nginx官方源(推荐)
[root@web01 ~]# vim /etc/yum.repos.d/nginx.repo 
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[root@web01 ~]# yum install nginx -y

2、nginx运行一个网站
[root@web01 conf.d]# gzip default.conf	
[root@web01 conf.d]# cat test.com.conf 
server {
			listen 80;
			server_name test.com;

location / {
				root /code;
				index index.html;
			}	
}

3、语法检查
[root@web01 conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

4、上传代码
[root@web01 code]# git clone https://gitee.com/linex/battlecity.git
[root@web01 code]# mv battlecity/* ./

5、重启服务
[root@web01 code]# systemctl restart nginx

6、访问测试
注意:使用域名请配置Windows Host劫持,否则无法访问自己配置的域名(host文件位置百度)

Three, nginx configuration files Detailed

user  nginx;								# Nginx进程的运行用户身份
worker_processes  1;						# Nginx运行的worker进程数
error_log  /var/log/nginx/error.log warn;	# Nginx错误日志存放的路径
pid        /var/run/nginx.pid;				# Nginx进程运行的PID号

events {
		worker_connections  1024;			# 每个worker进程能接受的最大连接数
		use epoll;
}

	
http {
		include       /etc/nginx/mime.types;
		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"';
		
#访问日志的路径  访问日志的存储格式是main格式, main格式在log_format中进行定义
		access_log  /var/log/nginx/access.log  main;		
	
		sendfile        on;
		#tcp_nopush     on;
		keepalive_timeout  65;					# 超时时间
		#gzip  on;
		include /etc/nginx/conf.d/*.conf;		# 包含  *.conf
		
		
#server<--定义网站
		server {
			listen       80;							# 监听80端口
			server_name  localhost;						# 网站的域名
			
			location / {								# 匹配网站的uri
				root   /usr/share/nginx/html;			# 返回资源的具体路径
				index  index.html index.htm;			# 返回的具体资源名称
			}
	}
Published 28 original articles · won praise 391 · views 50000 +

Guess you like

Origin blog.csdn.net/Dakshesh/article/details/104448544