• windows下搭建nginx服务器以及根目录的修改


    Nginx("engine x")是一款是由俄罗斯的程序设计师Igor Sysoev所开发高性能的 Web和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器。

    在高连接并发的情况下,Nginx是Apache服务器不错的替代品。

    一. nginx的安装

    下载windows版nginx (http://nginx.org/en/download.html),下载完成之后进行解压。

    二. nginx的配置

    进额U解压文件目录,可以看到有个conf文件夹,进入该文件夹找到nginx.conf并打开,开始对nginx进行配置。具体配置参数如下:

    在配置文件中找到

      server {

        .....

        .....

      }

    这个代码段,这段代码就是用来配置对应站点的。

    在代码段中找到server_name这一项然后把后面的域名改成我们要绑定的域名;root这一项就是指定的根目录,设置成我们指定的目录即可。

    具体如下:

      1 #user  nobody;
      2 worker_processes  1;
      3 
      4 #error_log  logs/error.log;
      5 #error_log  logs/error.log  notice;
      6 #error_log  logs/error.log  info;
      7 
      8 #pid        logs/nginx.pid;
      9 
     10 
     11 events {
     12     worker_connections  1024;
     13 }
     14 
     15 
     16 http {
     17     include       mime.types;
     18     default_type  application/octet-stream;
     19 
     20     #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
     21     #                  '$status $body_bytes_sent "$http_referer" '
     22     #                  '"$http_user_agent" "$http_x_forwarded_for"';
     23 
     24     #access_log  logs/access.log  main;
     25 
     26     sendfile        on;
     27     #tcp_nopush     on;
     28 
     29     #keepalive_timeout  0;
     30     keepalive_timeout  65;
     31 
     32     #gzip  on;
     33 
     34     server {
     35         listen       80;#监听端口
     36         server_name  localhost;#需要绑定的域名
     37 
     38         #charset koi8-r;
     39 
     40         #access_log  logs/host.access.log  main;
     41 
     42         location / {
     43             root   html;#站点根目录
     44             index  index.html index.htm;
     45         }
     46 
     47         #error_page  404              /404.html;
     48 
     49         # redirect server error pages to the static page /50x.html
     50         #
     51         error_page   500 502 503 504  /50x.html;
     52         location = /50x.html {
     53             root   html;
     54         }
     55 
     56         # proxy the PHP scripts to Apache listening on 127.0.0.1:80
     57         #
     58         #location ~ .php$ {
     59         #    proxy_pass   http://127.0.0.1;
     60         #}
     61 
     62         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
     63         #
     64         #location ~ .php$ {
     65         #    root           html;#站点根目录
     66         #    fastcgi_pass   127.0.0.1:9000;
     67         #    fastcgi_index  index.php;
     68         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
     69         #    include        fastcgi_params;
     70         #}
     71 
     72         # deny access to .htaccess files, if Apache's document root
     73         # concurs with nginx's one
     74         #
     75         #location ~ /.ht {
     76         #    deny  all;
     77         #}
     78     }
     79 
     80 
     81     # another virtual host using mix of IP-, name-, and port-based configuration
     82     #
     83     #server {
     84     #    listen       8000;
     85     #    listen       somename:8080;
     86     #    server_name  somename  alias  another.alias;
     87 
     88     #    location / {
     89     #        root   html;
     90     #        index  index.html index.htm;
     91     #    }
     92     #}
     93 
     94 
     95     # HTTPS server
     96     #
     97     #server {
     98     #    listen       443 ssl;
     99     #    server_name  localhost;
    100 
    101     #    ssl_certificate      cert.pem;
    102     #    ssl_certificate_key  cert.key;
    103 
    104     #    ssl_session_cache    shared:SSL:1m;
    105     #    ssl_session_timeout  5m;
    106 
    107     #    ssl_ciphers  HIGH:!aNULL:!MD5;
    108     #    ssl_prefer_server_ciphers  on;
    109 
    110     #    location / {
    111     #        root   html;
    112     #        index  index.html index.htm;
    113     #    }
    114     #}
    115 
    116 }
    View Code

    三. nginx的启动等操作

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

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


    如果遇到报错:

    bash: nginx: command not found

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

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

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

    启动之后如图所示:

  • 相关阅读:
    压缩信息立方体和集合技术内幕
    C++Dll Injection Tutorial
    BW BW项目的对象传输
    SDSD知识点列表
    MM提取MM模块配置的抛帐科目列表
    MMCollect some Transaction Key Problem
    BW数据装在的处理链的设计顺序
    asp.net 页面回车触发button按钮事件
    (转载)Linux多线程信号量的概念和使用
    (转载)如何查看安装的glibc版本
  • 原文地址:https://www.cnblogs.com/ciaociao/p/9224148.html
Copyright © 2020-2023  润新知