- 安装 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