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.2.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 80 -j ACCEPT

sudo service iptables restart

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

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

  (2)增加include vhost/*.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;#gzip  on;server {listen       80;server_name  localhost;#charset koi8-r;#access_log  logs/host.access.log  main;location / {root   html;index  index.html index.htm;}#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;#}}##########################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 80;
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.73/webapps/mmall;
#error_page 404 /404.html;
if ( $query_string ~* ".*[\;'\<\>].*" ){return 404;}
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 80;
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 404;}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 80;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 404 /404.html;if ( $query_string ~* ".*[\;'\<\>].*" ){return 404;}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-8;listen 80;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 404 /404.html;if ( $query_string ~* ".*[\;'\<\>].*" ){return 404;}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 80;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 404;}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

   

 

转载于:https://www.cnblogs.com/likevin/p/8997700.html

eshop6-nginx相关推荐

  1. nginx配置http、https访问,nginx指定ssl证书,阿里云腾讯云华为云设置nginx https安全访问

    nginx配置http.https访问 要设置https访问需要从对应的云厂商申请证书,并下载Nginx证书到服务器. 我这里从阿里云申请了免费的域名证书,然后将证书放置在服务器的/etc/ssl/. ...

  2. Web项目使用nginx实现代理端口访问,看这篇就够了

    在搭建服务器的时候,项目部署在tomcat上,要访问项目,则需要加上端口号,如何隐藏端口号来访问呢,这就用到了nginx. nginx可以在docker上安装,也可以在linux上安装,这里我建议使用 ...

  3. nginx介绍及常用功能

    什么是nginx nginx跟Apache一样,是一个web服务器(网站服务器),通过HTTP协议提供各种网络服务. Apache:重量级的,不支持高并发的服务器.在Apache上运行数以万计的并发访 ...

  4. Nginx搭建负载均衡集群

    (1).实验环境 youxi1 192.168.5.101 负载均衡器 youxi2 192.168.5.102 主机1 youxi3 192.168.5.103 主机2 (2).Nginx负载均衡策 ...

  5. 快速通过nginx配置域名访问

    配置nginx进行域名访问文件 在nginx安装目录下的conf目录下新建一个配置文件,比如你新加的域名为admin.hello.com,你希望通过这个域名访问admin项目,那么新建一个admin. ...

  6. Docker学习(七)-----Docker安装nginx

    基本安装 1. 拉取Nginx镜像 docker pull nginx:latest 2. 查看本地镜像列表(即可看到nginx) docker images 3. 运行容器 docker run - ...

  7. 使用阿里云服务器安装docker,并用nginx示例

    一.前言 之前对docker了解不多,自从使用了一次之后,就感觉这个产品对开发者实在是太友好了,可以迅速在Linux,window等平台部署服务.常见的有数据库,nginx,消息队列,redis等.利 ...

  8. Centos7.4安装Nginx

    Centos7.4安装Nginx 使用yum命令 一.安装准备 首先由于nginx的一些模块依赖一些lib库,所以在安装nginx之前,必须先安装这些lib库,这些依赖库主要有g++.gcc.open ...

  9. nginx将泛解析的匹配域名绑定到子目录配置方法

    应用场景: http://zzl.lteam.cn/ 访问/usr/local/boke/lteam.cn/zzl 目录下的 index.html http://lj.lteam.cn/ 访问/usr ...

  10. ubuntu搭建nginx环境

    1.首先给服务器上配置好JDK环境,之前有说过,在这就不多说了.本人安装的是JDK1.6. 2. 准备好2个TOMCAT,上传到服务器上.修改tomcat端口,所有端口必须不一致.本次演示用tomca ...

最新文章

  1. 最短路径·三:SPFA算法 HihoCoder - 1093 (spfa无向图)
  2. bitmap画文字 居中_【每日问答29】一键居中CAD表格中的文字
  3. 前后端分离时代,Java 程序员的变与不变!
  4. 让.net 2.0支持并行计算
  5. android开发的学习路线
  6. 视频播放加密功能的演示
  7. DirectX组件之---DirectShow介绍
  8. 如何通俗理解泊松分布?
  9. 关于mis系统开发的一些配置含义
  10. 八字易经算法之用JAVA实现最简单的称骨算命法
  11. java打包跳过test_Maven打包跳过测试的命令
  12. css实现多行文本时显示省略号
  13. 【Java】奇偶数判断
  14. 短视频询盘获客系统/源码搭建
  15. 慎用Java Collection的contains函数
  16. 【软件工程】什么?你还在复习软工但是不知道背哪里?速看!--电子科技大学2023年期末考试
  17. 华为自研系统鸿蒙,全球第一家!魅族官方中午12点宣布:看我力挺华为鸿蒙OS系统崛起...
  18. php安全新闻早八点-Microdoor-第四季
  19. 浅谈 Java 并发下的乐观锁
  20. Arduino Uno + APDS9930 实现手势控制LED灯亮灭、调光等

热门文章

  1. Android SurfaceFlinger中Fence机制--个人理解整理
  2. linux root 跑程序,linux下获得root权限运行程序
  3. 西门子smart200 圆弧插补 整合画图程序 2轴3轴 二轴版本 适合西门子SMART200 ST20 ST30 ST40 ST60 三轴版本 适合西门子SMART200 ST40 ST60
  4. Win10怎么将用户文件夹改名(如中文改成英文名)
  5. 跨立实验判断线段是否相交-POJ3304
  6. gitlab安装及其汉化版
  7. 纵向联邦学习的挑战与展望
  8. 服务器托管全解 甩手掌柜却更高效稳定
  9. 数学小知识点整理(TBC)
  10. Java详解:javaee教程文档