安装(mac):关于brew  的问题: http://www.cnblogs.com/adouwt/p/8042201.html

brew install nginx 

启动:

brew services start  nginx 

重启:

brew services restart  nginx 

停止:

brew services stop nginx 

修改配置文件:

安装成功后,会在/etc/nginx 有个 nginx.conf 文件,这里做一些反向代理的操作

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 utf-8;      // 编码格式#access_log  logs/host.access.log  main;root   /Users/wangtao/Desktop/my-test-files;  // 访问的根路径  这个是我本地的桌面的某个文件夹的地址index  iindex.html iindex.htm;                    // 默认访问的文件, 我把它改了不是 index.html 主要就是想访问的是这个文件夹,不是某个默认的文件
# 开启目录浏览autoindex on;autoindex_exact_size off;autoindex_localtime on;#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;#    }#}include vhosts/*.conf;  // 这里include 的配置  意思是 同级目录下 vhost 的文件夹下所有 .conf 的配置文件
}

知道这些简单的配置知识,我们就可以进行简单的做一些反向代理了,可以在这个 vhost 下新建我们的配置文件,当然这个文件夹是可以随便取名字的。我们新建一个文件叫myself.conf

server {listen 80; // 反向代理的时候,基本都是这个80端口,服务启动的是那个端口就代理哪个端口server_name test.itlab.wang;  // 访问的域名 location / {root /Users/wangtao/it-cloud-lab/www-mobile-client-phone/dist; // 访问的根目录地址,我这里是webpack 打包的一个地址index index.html; // 默认访问的 index.html 的文件}
}

修改配置文件后,需要重新加载下配置nginx文件,  nginx -s reload   如果这个nginx 服务是root 权限的时候,加sudo 启动  sudo nginx -s reload  ,这时候需要输入计算机密码

这个命令可以按字面意思解释: 保存并重载

linux (阿里云服务器):

安装依赖:

yum install -y epel-*
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel

安装nginxyum install nginx  安装好后就是 修改配置文件 。做一些反向代理的操作

下面的就是 将9000端口的服务代理到80端口,通过访问 csa.scampus.cn 就可以看到程序了

server {
  listen 80;
  server_name csa.scampus.cn;
  root /usr/share/nginx/html;
  include /etc/nginx/default.d/*.conf;
  location / {
    proxy_pass http://127.0.0.1:9000;
  }
  error_page 500 502 503 504 /50x.html;
  location = /50x.html{
  }
 }

windows 安装

一. 下载

http://nginx.org/
下载后解压,如下

二. 修改配置文件

nginx配置文件在 nginx-1.14.0\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;#gzip  on;server {listen       8008;server_name  localhost;#charset koi8-r;#access_log  logs/host.access.log  main;location / {root   E:\vue\vue-dist\dist;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;server_name  localhost;location / {root   E:\mystatic_folder;index  iindex.html iindex.htm;autoindex on;        }}# 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;#    }#}}

三. 启动

注意不要直接双击nginx.exe,这样会导致修改配置后重启、停止nginx无效,需要手动关闭任务管理器内的所有nginx进程
在nginx.exe目录,打开命令行工具,用命令 启动/关闭/重启nginx 
start nginx : 启动nginx
nginx -s reload  :修改配置后重新加载生效
nginx -s reopen  :重新打开日志文件
nginx -t -c /path/to/nginx.conf 测试nginx配置文件是否正确

关闭nginx:
nginx -s stop  :快速停止nginx
nginx -s quit  :完整有序的停止nginx

如果遇到报错:

bash: nginx: command not found

有可能是你再linux命令行环境下运行了windows命令,

如果你之前是允许 nginx -s reload报错, 试下 ./nginx -s reload

或者 用windows系统自带命令行工具运行

nginx 的基本配置相关推荐

  1. http响应Last-Modified和ETag以及Apache和Nginx中的配置

    基础知识 1) 什么是"Last-Modified"? 在浏览器第一次请求某一个URL时,服务器端的返回状态会是200,内容是你请求的资源,同时有一个Last-Modified的属 ...

  2. Nginx 安装及配置

    概念 了解 Nginx 的基本概念 安装 apt-get install nginx # Ubuntu yum install nginx -y # CentOS 配置文件 nginx -t # 检查 ...

  3. linux nginx php 目录权限,Nginx环境中配置网站目录权限设置

    在Nginx与php环境下,务必要设置好Nginx目录权限,安全的目录权限设置,将是网站安全的一道屏障,有需要的朋友做个参考吧. 配置权限的原则是,在保证网站正常运行下,尽量给最低权限. nginx目 ...

  4. 使用Nginx为Leanote配置Https

    生成SSL证书 可以在网上买一个, 或者自己做一个. 这里有一个shell脚本可以自动生成证书: #!/bin/sh# create self-signed server certificate:re ...

  5. Linux服务器上最简单的Nginx反向代理配置

    2019独角兽企业重金招聘Python工程师标准>>> Nginx不但是一款高性能的Web服务器,也是高性能的反向代理服务器.简单的可以理解为直接让当前的访问地址跳转到其他的网站上去 ...

  6. Nginx+UWSGI+Django配置全过程

    Nginx + uwsgi + Django 安装配置 一.安装Nginx uwsgi Django 安装tengine yum install pcre-devel -y wget http://t ...

  7. 利用nginx泛域名解析配置二级域名和多域名

    利用nginx泛域名解析配置二级域名和多域名网站的目录结构为 html ├── bbs └── wwwhtml为nginx的安装目录下默认的存放源代码的路径.bbs为论坛程序源代码路径 www为主页程 ...

  8. Nginx(九)-- Nginx实际使用配置

    1.由于在nginx中需要配置很多东西,就会使得nginx.conf配置文件过于臃肿,所以我们会将配置文件合理的切分.大体的配置依然在nginx.conf中,其他的配置会放在etc下面的目录中. 2. ...

  9. Nginx之https配置

    14.1. 对称加密 安全隐患:钥匙除我之外,还有多个人拥有.泄露风险较大,钥匙传递的过程风险较大 14.2. 非对称加密 优缺点:私钥很安全.但是非对称算法开销很大,大批量应用于业务,会导致性能成本 ...

  10. windows下nginx安装、配置与使用

    目前国内各大门户网站已经部署了Nginx,如新浪.网易.腾讯等:国内几个重要的视频分享网站也部署了Nginx,如六房间.酷6等.新近发现Nginx 技术在国内日趋火热,越来越多的网站开始部署Nginx ...

最新文章

  1. mysql char varchar text 对比
  2. Android服务之Service(其一)
  3. Windows 2000配置Web服务器
  4. 利用云安监控和管理云
  5. 和菜鸟一起学linux之DBUS基础学习记录
  6. CF835E-The penguin‘s game【交互】
  7. [jQuery]JQuery一个对象可以同时绑定多个事件,这是如何实现的?
  8. 【需求工程】系统服务与系统约束
  9. 二十三种设计模式[6] - 适配器模式(Adapter Pattern)
  10. Linux 将本地文件上传Linux服务器, 即ssh 命令上传本地文件
  11. k均值聚类算法考试例题_k均值算法(k均值聚类算法计算题)
  12. 服务器手机远程控制,向日葵远程控制让手机也能远程管理
  13. 深入理解Solaris X64系统调用
  14. 潜伏在大厂中“摸鱼”的打工人
  15. 一维消消乐c语言数据结构,Python数据结构:一维开心消消乐
  16. Oracle 安装 docker,使用docker安装Oracle 12c database(一)
  17. STM32的USART中RTS、CTS的作用和意义
  18. ubuntu软件:录制视频和截图工具,压缩视频
  19. QIIME 2教程. 11元数据Metadata(2021.2)
  20. IE 插件 数字签名

热门文章

  1. 深度神经网络 卷积神经网络_改善深度神经网络
  2. python如何获得列表中某个元素的index
  3. vm14远程连接服务器,VisualVM 远程连接服务器
  4. flutter 判断是不是调试模式_Flutter之撸一个漂亮的登录界面的总结
  5. 无线服务器软件,无线局域网AAA服务器的软件设计与实现
  6. [图灵程序设计丛书].流畅的Python.revise11.pdf
  7. docker 容器无法连接外网
  8. 百度亮相NeurIPS 首届Expo:向世界科普了中国自动机器学习框架
  9. oracle数据库之间数据同步
  10. Chrome 52 将支持 ES7:Canary 通道已上线