原文链接:nginx配置前端网站

0.前言
上面一篇文章中,简单介绍了windows下下载安装nginx。这篇文章继续介绍下nginx下配置前端网站等。

1.配置文件
nginx的配置文件在下面的目录下:

打开后,默认配置如下:

#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_user [request" '#                  'body_bytes_sent "$http_referer" '#                  '"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;#}}# 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;#    }#}
}

主要是改

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

这表示默认的网站是nginx的html文件夹。

假如我们写的前端项目文件打包后是dist。我们把这个dist文件夹放在nginx目录下,然后修改为:

location / {
root dits;
index index.html index.htm;
}

这样就可以访问我们的前端文件了。

2.配置启动
如果要重启,或者停止服务都必须在dos命令下手动重启或停止,比较麻烦,我用批处理写了重启和停止命令:如下

stop.bat

@echo offcd %~dp0nginx -s quit

restart.bat

@echo offcd %~dp0nginx -s reload

nginx配置前端网站相关推荐

  1. 使用Dockerfile+nginx配置前端项目

    使用Dockerfile+nginx配置前端项目 创建文件: ├── default.conf ├── Dockerfile ├── html │ ├── index2.html │ └── inde ...

  2. docker使用nginx配置前端页面

    docker使用nginx配置前端页面 1.拉取镜像 docker pull nginx:latest 2. 启动容器 $ docker run -itd --name test-nginx -p 2 ...

  3. NGINX配置PHP网站

    NGINX配置PHP网站 NGINX配置PHP网站 源码安装NGINX 安装PHP 修改PHP参数 重启PHP 修改nginx配置文件 重启NGINX 测试 解决报错问题 NGINX配置PHP网站 源 ...

  4. nginx配置前端反向代理

    本地这里有两个端口: 8080:前端页面 80:后端接口 在nginx配置 listen 8888;server_name 127.0.0.1;location / {root html;proxy_ ...

  5. Nginx配置web网站维护页面--->访问任意页面都要跳转到维护页面

    1.网站维护页面背景 网站升级需要停服的情况下,需要准备维护页面,单单准备一个维护页面也是不够的,很多用户会把登陆页面比如login.html收藏,这时访问项目就会出现404,因此还需要配置不管访问什 ...

  6. nginx配置前端不缓存

    修改nginx配置文件,直接在loacation模块下加入如下参数: 配置页面不缓存html和htm结尾的文件 if ($request_filename ~* .*\.(?:htm|html)$) ...

  7. nginx 配置后网站图片加载出来一半或者不出来

    项目进行nginx反向代理后发现图片和js.css等加载很慢,甚至加载不出来. 然后查看nginx的log,发现错误如下: [html] view plaincopy 2016/06/30 15:31 ...

  8. nginx配合前端实现网站分流 ABtest

    前端随机生成0-99的cookie,通过nginx分配10%的流量 nginx配置 前端生成cookie (function(){function random(min, max) {return M ...

  9. 轻松搞定 Nginx 配置的好工具!

    轻轻松松,配置高性能.安全.稳定的 Nginx 服务器 无论是前端.后端.还是运维同学,都一定听说过 Nginx,一个高性能的 HTTP 和 反向代理 web 服务器,同时也提供了IMAP/POP3/ ...

最新文章

  1. iOS开发-照片选择
  2. 含有PCA动画演示的帖子,需要多读几遍的经典
  3. 用Python实现Gauss-Jordan求逆矩阵
  4. OpenCV学习:改变图像的对比度和亮度
  5. MongoDB和Redis区别
  6. wps大纲栏显示在右边_miui12通知栏在哪
  7. 计算机网络(谢希仁第八版)第四章:网络层
  8. display和show的区别
  9. 工作114:传参控制
  10. jquey-整屏滚动的制作过程
  11. python构建简单神经网络_Python构建一个简单的神经网络,Pytorch,搭建
  12. spark BlockManager如何实现Broadcast广播
  13. Logstash filter 插件之 grok
  14. 百度语音合成data:audio/x-mpeg;base64转mp3
  15. 盖洛普优势理论自我分析
  16. 商业变现永不眠(一) — 什么是决定商业化路径的底层逻辑?
  17. Vero tempora officia nesciunt unde consequuntuIncidunt voluptatem minus earum.r.
  18. 黄牛落泪!全球显卡价格纷纷跳水,高价囤货滞销
  19. Java BMI计算程序
  20. Win8下装XP双系统

热门文章

  1. python中button对象的方法_Python cmds.shelfButton方法代码示例
  2. 「GoTeam 招聘时间」传音移动互联 容器开发(上海)
  3. 计算机组成原理 存储器
  4. python星空画法教程,PS后期打造一张惊艳的星空风景照片后期调色教程
  5. 时间与运动-MATHLAB机器人学、机器视觉与控制
  6. 19年深圳杯D题之爬取电视收视率排行榜
  7. mac 设置mysql登录快捷键_史上最详细的苹果Macbook快捷键使用
  8. Web Scraper入门
  9. w10取消自带杀毒服务器,win10家庭版关闭杀毒服务如何设置_win10家庭版怎么关闭自带杀毒系统-win7之家...
  10. java 计算器 junit测试_Java Junit测试