1. 什么是Nginx?
Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,在BSD-like 协议下发行。其特点是占有内存少,并发能力强,事实上nginx的并发能力在同类型的网页服务器中表现较好。
并发能力: 50,000 。
2. 为什么使用nginx?
- Nginx 是高性能的 HTTP 和反向代理的web服务器,处理高并发能力是十分强大的,能经受高负 载的考验,有报告表明能支持高达 50,000 个并发连接数。
- Nginx支持热部署,启动简单,可以做到7*24不间断运行。几个月都不需要重新启动。

3. 安装nginx
nginx可以独立安装在一台服务器--也可以和项目在同一个服务器。
3.1 安装nginx的依赖插件
yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
如果yum这个命令不能用,请看这篇:Linux查看端口号命令以及yum源无法使用的解决方法-CSDN博客
3.2 下载nginx
nginx: download

3.3 创建一个目录作为nginx的安装路径
mkdir /usr/nginx3.4 解压
tar -zxvf nginx-1.26.1.tar.gz3.5 进入解压后的目录
tar -zxvf nginx-1.26.1.tar.gz3.6 指定nginx的安装路径
 ./configure --prefix=/usr/nginx3.7 编译和安装nginx
make install3.8 启动nginx
nginx  启动
nginx -s stop  关闭
nginx -s reload 重新加载配置文件
3.9 访问nginx
http://nginx所在的ip:nginx的端口/

默认端口号:80
4. nginx目录结构

5.nginx配置文件
在/usr/nginx/conf/nginx.conf中。
#user  nobody; 
#工作的线程数
worker_processes  1;#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {# 每个工作对象允许的连接数worker_connections  1024;
}http {include       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"';#access_log  logs/access.log  main;sendfile        on;#tcp_nopush     on;#keepalive_timeout  0;keepalive_timeout  65;server {listen 81;server_name localhost;location /{root static;index main.html;}}#gzip  on;server {listen       80; # 监听的端口号server_name  localhost; # 监听的主机名.域名#charset koi8-r;#access_log  logs/host.access.log  main;# 资源/ location / {root   html; #根目录index  index.html main.html; # 资源}#error_page  404              /404.html;# redirect server error pages to the static page /50x.html#error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {#    proxy_pass   http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {#    root           html;#    fastcgi_pass   127.0.0.1:9000;#    fastcgi_index  index.php;#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;#    include        fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {#    deny  all;#}}# another virtual host using mix of IP-, name-, and port-based configuration##server {#    listen       8000;#    listen       somename:8080;#    server_name  somename  alias  another.alias;#    location / {#        root   html;#        index  index.html index.htm;#    }#}# HTTPS server##server {#    listen       443 ssl;#    server_name  localhost;#    ssl_certificate      cert.pem;#    ssl_certificate_key  cert.key;#    ssl_session_cache    shared:SSL:1m;#    ssl_session_timeout  5m;#    ssl_ciphers  HIGH:!aNULL:!MD5;#    ssl_prefer_server_ciphers  on;#    location / {#        root   html;#        index  index.html index.htm;#    }#}}