1、在nginx官网http://nginx.org/下载nginx
2、
3、选择一个版本,我用的是1.6.3
4、解压缩文件,然后点击nginx.exe,运行窗口会一闪而过,在config--nginx.config里面的默认端口配置是80端口,所以有可能80端口会占用,但是运行窗口也不会提醒你的错误,所以最好用命令的模式进行启动nignx
5、命令:
nginx -s -stop/quit 关闭nginx
如果没有错误,说明成功了,这时可以在浏览器输入:loclhost,会出现welcome to niginx的网页。
6、配置--config--nginx.config
#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;
//用户上传字节数不能大于20M
client_max_body_size 20m;
//配置日志的输出格式
log_format access '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent $request_body "$http_referer" "$http_user_agent" $http_x_forwarded_for';
#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;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
//当用户访问 8888端口的时候,会反向代理到9011端口
server {
listen 8888;//监听的端口,默认是80
server_name localhost;//服务器名称
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_set_header Host $host:8888;
proxy_set_header X_Real_IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://127.0.0.1:9011; //代理的地址
}
}
//-----------------------------------下面是自带的-------------------------------------------------------------------
# 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;
# }
#}
}
7、启动nginx
8、浏览器输入loclhost:8888,页面将跳转到127.0.0.1:9011的网站