- 安裝 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;
events {
worker_connections 1024;
}
###設定http服務器,利用它的反向代理功能提供負載均衡支持
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;
}
}
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:
}
}
}
#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
> start nginx
> nginx -s reload
> nginx -s stop