第一步配置 hosts
C:\Windows\System32\drivers\etc
hosts
127.0.0.1 www.xxxx.com
127.0.0.1 cloud.xxxx.com
第二步配置 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; #最大连接数,默认为512
accept_mutex on; #设置网路连接序列化,防止惊群现象发生,默认为on
multi_accept on; #设置一个进程是否同时接受多个网络连接,默认为off
}
http {
include mime.types; #文件扩展名与文件类型映射表
default_type application/octet-stream;#默认文件类型,默认为text/plain
#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; #允许sendfile方式传输文件,默认为off,可以在http块,server块,location块
#tcp_nopush on;
#keepalive_timeout 0;
#keepalive_timeout 65;
#gzip on;
#设定实际的服务器列表
upstream wit_yrp_server{
server 192.168.13.185:9009;
}
server {
listen 80;
server_name www.xxx.com;
#编码格式
charset utf-8;
#access_log logs/host.access.log main;
#反向代理的路径(和upstream绑定),location 后面设置映射的路径
location / {
proxy_pass http://192.168.13.185:9009;
#deny 127.0.0.1; #拒绝的ip
#allow 172.18.5.54; #允许的ip
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
#禁止访问 .htxxx 文件
#location ~ /\.ht {
# deny all;
# }
#错误处理页面(可选择性配置)
#error_page 404 /404.html;
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root html;
#}
}
server {
listen 80;
server_name cloud.xxx.com;
#编码格式
charset utf-8;
#access_log logs/host.access.log main;
#反向代理的路径(和upstream绑定),location 后面设置映射的路径
location / {
proxy_pass http://192.168.13.185:9008;
#deny 127.0.0.1; #拒绝的ip
#allow 172.18.5.54; #允许的ip
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
#禁止访问 .htxxx 文件
#location ~ /\.ht {
# deny all;
# }
#错误处理页面(可选择性配置)
#error_page 404 /404.html;
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root html;
#}
}
# 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;
# }
#}
}
nginx 命令
-
在nginx根目录下启动nginx命令:start nginx;
-
查看nginx是否启动
(1) 查看logs目录下是否有nginx.pid文件,如果有说明nginx是启动状态的,如果没有说明nginx已经停止
(2) 查看80端口是否启动,查看命令是:netstat -ano|findstr :80 ;
-
修改配置文件后重启nginx命令:nginx -s reload;
-
停止nginx命令:nginx -s stop