1. Nginx 是什么?

  Nginx 是一款轻量级Web服务器,也是一款反向代理服务器

2. Nginx 能干什么

  可以直接支持Rails 和PHP 程序

  可以作为HTTP反向代理

  作为负载均衡服务器

  作为邮件代理服务器

  帮助前端实现动静分离

3. Nginx 特点

  高稳定

  高性能

  资源占用少

  功能丰富

  模块化结构

  支持热部署

4. Nginx 安装

  (1) 安装gcc (yum install gcc)

备注:可以输入gcc -v 查询版本信息,看系统是否自带安装

  (2) 安装pcre (yum install pcre-devel) 

  (3) 安装zlib (yum install zlib zlib-devel)

  (4) 安装openssl (yum install openssh openssh-devel)

  (5) 下载源码包,选择稳定版本(http://www.nginx.org/) 

wget http://nginx.org/download/nginx-1.10.2.tar.gz 
tar -zxvf nginx-1.10..tar.gz

  (6) 进入nginx目录之后执行./configure

    也可以指定安装目录,增加参数--prefix=/usr/nginx

    如果不指定路径,可以通过whereis nginx进行查询

    默认安装在/usr/local/nginx

  (7)  继续执行make

  (8) 继续执行make install

5. nginx 常用命令

  (1). 测试配置文件

    安装目录下的/nginx/sbin/nginx -t

  (2). 启动命令

    安装路径下的/nginx/sbin/nginx

  (3).停止命令

    安装路径下的/nginx/sbin/nginx -s stop 或者 nginx -s quit

  (4). 重启命令

    安装路径下的/nginx/sbin/nginx -s reload

  (5). 查看进程命令

    ps -ef | grep nginx

  (6). 平滑重启

    kill -HUP {Nginx 主进程号(既查看进程命令查到的PID)}

  (7). 增加防火墙权限

sudo vi /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW -m tcp --dport  -j ACCEPT

sudo service iptables restart

6. 虚拟域名配置及测试验证

  (1)编辑sudo vi /usr/local/nginx/conf/nginx.conf

  (2)增加include vhost/*.conf

#user  nobody;
worker_processes ; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections ;
} 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 ;
keepalive_timeout ; #gzip on; server {
listen ;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / {
root html;
index index.html index.htm;
} #error_page /.html; # redirect server error pages to the static page /50x.html
#
error_page /50x.html;
location = /50x.html {
root html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:;
# 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;
#} } ##########################vhost#####################################
include vhost/*.conf; # 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;
# }
#} }

  (3)在/usr/local/nginx/conf/ 目录新建vhost文件夹,既:/usr/local/nginx/conf/vhost

  (4)创建域名转发配置文件,点击查看详情

admin.happymmall.com.conf
server {
listen ;
autoindex on;
server_name admin.happymmall.com;
access_log /usr/local/nginx/logs/access.log combined;
index index.html index.htm index.jsp index.php;
#root /devsoft/apache-tomcat-7.0./webapps/mmall;
#error_page /.html;
if ( $query_string ~* ".*[\;'\<\>].*" ){
return ;
}
location = / {
root /product/front/mmall_admin_fe/dist/view;
index index.html;
}
location ~ .*\.(html|htm)$ {
root /product/front/mmall_admin_fe/dist/view;
index index.html;
}
location / {
proxy_pass http://127.0.0.1:8080/;
add_header Access-Control-Allow-Origin '*';
}
}

happymmall.com.conf 
server {
listen ;
autoindex on;
server_name happymmall.com www.happymmall.com;
access_log /usr/local/nginx/logs/access.log combined;
index index.html index.htm index.jsp index.php;
if ( $query_string ~* ".*[\;'\<\>].*" ){
return ;
} location = / {
root /product/front/mmall_fe/dist/view;
index index.html;
} location ~ .*\.html$ {
root /product/front/mmall_fe/dist/view;
index index.html;
} location / {
proxy_pass http://127.0.0.1:8080/;
} location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
proxy_pass http://127.0.0.1:8080;
expires 30d;
} location ~ .*\.(js|css)?$ {
proxy_pass http://127.0.0.1:8080;
expires 7d;
}
}
img.happymmall.com.conf 

server {
listen ;
autoindex off;
server_name img.happymmall.com;
access_log /usr/local/nginx/logs/access.log combined;
index index.html index.htm index.jsp index.php;
#error_page /.html;
if ( $query_string ~* ".*[\;'\<\>].*" ){
return ;
} location ~ /(mmall_fe|mmall_admin_fe)/dist/view/* {
deny all;
} location / {
root /product/ftpfile/img/;
add_header Access-Control-Allow-Origin *;
}
}

learning.happymmall.com.conf

server {
default_type 'text/html';
charset utf-;
listen ;
autoindex on;
server_name learning.happymmall.com;
access_log /usr/local/nginx/logs/access.log combined;
index index.html index.htm index.jsp index.php;
#error_page /.html;
if ( $query_string ~* ".*[\;'\<\>].*" ){
return ;
} location ~ /(mmall_fe|mmall_admin_fe)/dist/view/* {
deny all;
} location / {
root /product/ftpfile/learning/;
add_header Access-Control-Allow-Origin *;
}
}

s.happymmall.com.conf

server {
listen ;
autoindex off;
server_name s.happymmall.com;
access_log /usr/local/nginx/logs/access.log combined;
index index.html index.htm index.jsp index.php;
if ( $query_string ~* ".*[\;'\<\>].*" ){
return ;
} location ~ /(mmall_fe|mmall_admin_fe)/dist/view/* {
deny all;
} location / {
root /product/front/;
add_header Access-Control-Allow-Origin *;
}
}

  (5)启动(重启)验证

    启动:${nginx}/sbin/nginx

    重启:${nginx}/sbin/nginx -s reload

${nginx} 安装路径, /usr/local/nginx

  (6)访问验证

    使用默认80端口访问验证:http://localhost:80 或http://127.0.0.1:80 ,本次验证,我们使用的虚拟机因此http://172.31.8.112:80

  

7. Nginx 虚拟域名配置

8. Nginx 本地搭建环境注意事项

(1). 可以配置域名转发,但是请注意要配置host,并且使host生效之后才可以,设置完成之后要重启浏览器

(2). Linux

  sudo vi /etc/hosts

  添加好对应的域名及IP

   

 

eshop6-nginx的更多相关文章

  1. accept_mutex与性能的关系 (nginx)

    注:运行环境CentOS 6+   背景      在对启动了20个worker的nginx进行压力测试的时候发现:如果把配置文件中event配置块中的accept_mutex开关打开(1.11.3版 ...

  2. nginx配置反向代理或跳转出现400问题处理记录

    午休完上班后,同事说测试站点访问接口出现400 Bad Request  Request Header Or Cookie Too Large提示,心想还好是测试服务器出现问题,影响不大,不过也赶紧上 ...

  3. 【大型网站技术实践】初级篇:借助Nginx搭建反向代理服务器

    一.反向代理:Web服务器的“经纪人” 1.1 反向代理初印象 反向代理(Reverse Proxy)方式是指以代理服务器来接受internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从 ...

  4. Docker笔记一:基于Docker容器构建并运行 nginx + php + mysql ( mariadb ) 服务环境

    首先为什么要自己编写Dockerfile来构建 nginx.php.mariadb这三个镜像呢?一是希望更深入了解Dockerfile的使用,也就能初步了解docker镜像是如何被构建的:二是希望将来 ...

  5. nginx+php的使用

    原文来自:windows下配置nginx+php环境 按照他的步骤走,亲测可用! 但是这里他后面说的根目录可能有些人有点懵. 其实在设置的时候就设置了: 网站根目录就是www这个目录,如果没创建请自行 ...

  6. nginx的使用

    1.nginx的下载 解压后文件目录: 2.nginx的常用命令 nginx -s stop 强制关闭  nginx -s quit 安全关闭  nginx -s reload 改变配置文件的时候,重 ...

  7. nginx+iis+redis+Task.MainForm构建分布式架构 之 (redis存储分布式共享的session及共享session运作流程)

    本次要分享的是利用windows+nginx+iis+redis+Task.MainForm组建分布式架构,上一篇分享文章制作是在windows上使用的nginx,一般正式发布的时候是在linux来配 ...

  8. windows+nginx+iis+redis+Task.MainForm构建分布式架构 之 (nginx+iis构建服务集群)

    本次要分享的是利用windows+nginx+iis+redis+Task.MainForm组建分布式架构,由标题就能看出此内容不是一篇分享文章能说完的,所以我打算分几篇分享文章来讲解,一步一步实现分 ...

  9. nginx源码分析之模块初始化

    在nginx启动过程中,模块的初始化是整个启动过程中的重要部分,而且了解了模块初始化的过程对应后面具体分析各个模块会有事半功倍的效果.在我看来,分析源码来了解模块的初始化是最直接不过的了,所以下面主要 ...

  10. Nginx如何处理一个请求

    看了下nginx的官方文档,其中nginx如何处理一个请求讲解的很好,现在贴出来分享下.Nginx首先选定由哪一个虚拟主机来处理请求.让我们从一个简单的配置(其中全部3个虚拟主机都在端口*:80上监听 ...

随机推荐

  1. burpsuite使用--暴力破解

    测试靶机:dvwa 浏览器开启代理,使用burpsuite拦截: 并将拦截到的内容发送到intruder进行暴力破解 右边的Add$和Clear$都是选择爆破范围的操作,一个是选择,一个是清除,这里只 ...

  2. 八 Struts2访问Servlet的API方式三:接口注入

    Struts2访问Servlet的API方式三:接口注入 通过实现ServletRequestAware, ServletContextAware 接口,拿到Request.ServletContex ...

  3. Linux命令:route命令

    route显示或修改IP路由表 route -n:显示路由信息,使用数字格式显示,不反解地址到主机名 #route -n Kernel IP routing table Destination Gat ...

  4. Linux命令:vi | vim命令

    vim - vi 增强版.文本编辑器 格式:vim [options] [file ..] 说明:如果file存在,文件被打开并显示内容,如果文件不存在,当编辑后第一次存盘时创建它 [options] ...

  5. [NOI 2011]NOI 嘉年华

    Description 题库链接 给你 \(n\) 个区间,让你选出其中一些分为两组,要求两组区间不能有交集,组内可以有交集.让你最大化两组之间区间个数较小的那一组的选取区间个数.以及对于每个区间 \ ...

  6. 解题报告:luogu P2220

    指挥使走后一脸懵逼,然后想起了一道水\(SB\)的省选题. 这是毒瘤乘法分配率的应用,似乎还有一篇,算是入门题. 对了,这题连接:P2220 [HAOI2012]容易题 然而蒟蒻还是先自闭了一会... ...

  7. php实现简单链式操作mysql数据库类

    <?php $dbConfig = require_once(dirname(__FILE__).'/config.php'); class Db{     public $conn;      ...

  8. 用Navicat连接阿里云ECS服务器上的MySQL数据库,连接不上,并且报10060错误

    设置远程访问(使用root密码): grant all privileges on . to 'root' @'%' identified by '123456'; flush privileges; ...

  9. ServletContext简介

    什么是SercletContext ServletContext官方叫servlet上下文.服务器会为每一个工程创建一个对象,这个对象就是ServletContext对象.这个对象全局唯一,而且工程内 ...

  10. 本周总结(19年暑假)—— Part7

    日期:2019.8.25 博客期:113 星期日