nginx配置起服務

  • 安裝 nginx;
  • 配置 nginx.conf 文件
    • 在根目錄下找到 conf 文件夾下的 nginx.conf 文件,根據自己的需求做如下配置(含說明):
#user  nobody; //nginx用戶及組:用戶組。windows下不指定
worker_processes  1; //工作進程:數目。

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
//錯誤日誌:存放路徑。

#pid        logs/nginx.pid;
//pid(進程標識符):存放路勁

events {
    worker_connections  1024;
    //每個工作進程最大連接數量
}

###設定http服務器,利用它的反向代理功能提供負載均衡支持
//一個http裏面可以配置多個server 。監聽端口可以一樣,只要域名和路徑不一樣就可以了

http {
    include       mime.types;//設定mime類型,類型由mime.type文件定義
    default_type  application/octet-stream;

   ##配置虛擬機
  server {
  listen      80;//監聽端口
        server_name testapp.zhlc.com; //訪問域名

        root   E:/webstorm/zhlc_h5/debug/; //路徑:自己的代碼源文件目錄
        index  index.html index.htm; //首頁
        location ~ \.(jpg|jpeg|png|gif|js|css|ico|txt|xml|swf|wav|eot|ttf|otf|woff|svg|woff2) { //對以jpg……等結尾的地址進行負載均衡
                expires 30d;
        }
   }

  server {
      listen 8080;
      server_name ngx-ha.***img.com;
      location / {
      stub_status on;
      access_log off;
      }
  }

  server {
      listen 80;
      server_name imgsrc1.***.net;
      root html;
  }

  server {
      listen 80;
      server_name ***.com w.***.com;
      # access_log /usr/local/nginx/logs/access_log main;
      location / {
      rewrite ^(.*)$ http://www.***.com/ ;
        }
  }

}




//純配置代碼:

#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;

  server {
        listen      80;
        server_name testapp.zhlc.com;

        root   E:/webstorm/zhlc_h5/debug/;
        index  index.html index.htm;
        location ~ \.(jpg|jpeg|png|gif|js|css|ico|txt|xml|swf|wav|eot|ttf|otf|woff|svg|woff2) {
                expires 30d;
        }
   }
 }


  • 配置 host ,打開switchHosts,切換host:
#本機(迴環地址)  域名
127.0.0.1 xxx.xxx.com 
  • 在nginx目錄下打開cli窗口,起服務
> start nginx //起服務
> nginx -s reload //重啓服務
> nginx -s stop //停止服務
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章