①官方下载。
解压到相应的目录,比如我是d盘 然后修改目录名字为nginx
②安装
解压目录,双击nginx.exe,启动nginx。此时 直接在浏览器地址栏输入:localhost 便能看到 欢迎页面,说明你虚拟主机已经搭建好了。
③配置,安装目录conf文件夹,配置文件nginx.conf
下面为本网站配置文件摘录,其中前三个域名为动态代理tomcat,static域名为静态映射。
worker_processes 1; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } ## www.song-z.com server { listen 80; server_name song-z.com www.song-z.com; access_log logs/www.song-z.com.access.log main; error_log logs/www.song-z.com.error.log; location / { proxy_pass http://localhost:13201; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } ## admin.song-z.com server { listen 80; server_name admin.song-z.com; access_log logs/admin.song-z.com.access.log main; error_log logs/admin.song-z.com.error.log; location / { proxy_pass http://localhost:13201/admin/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } ## file.song-z.com server { listen 80; server_name file.song-z.com; access_log logs/file.song-z.com.access.log main; error_log logs/file.song-z.com.error.log; location / { proxy_pass http://localhost:13201/file/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } ## static.song-z.com server { listen 80; server_name static.song-z.com; access_log logs/static.song-z.com.access.log main; error_log logs/static.song-z.com.error.log; location / { root D:/data/static/songz; } } }
④设置为开机服务
nginx未提供Win下的服务命令,只能通过双击启动,然后命令行管理。
毕竟每次都双击启动,命令行操作,不是很方便,可以考虑第三方软件来进行安装为win服务,选用Windows Service Wrapper,详细操作请参考:-->传送门<--。