1.下载并安装nginx

到nginx官网上下载相应的安装包,http://nginx.org/en/download.html;

下载之后进行解压,将解压后的文件放到自己心仪的目录下,如下图所示:

至此,下载和安装nginx就已经完成了。

2.启动nginx

打开cmd命令窗口,切换到nginx解压目录下,输入命令 start nginx ,回车即可,此时可能会有一个黑色的弹窗一闪而过,不用理会。

打开浏览器,输入网址 http://localhost:80;回车,如果出现以下页面说明启动成功:

3.nginx常用命令

命令 描述
nginx -h 查看nginx帮助
nginx -v 查看nginx版本
nginx -t 测试nginx配置
nginx -T 测试nginx帮助,并打印配置信息
nginx -s reload 重新加载配置文件,平滑启动nginx
nginx -s stop 快速停止nginx
nginx -s quit 完整有序的停止nginx

4.nginx基本配置

nginx的配置文件在nginx解压目录/conf/nginx.conf,用编辑器打开即可进行相关配置


#user nobody; # 设置nginx服务的系统使用用户
worker_processes 1; # 工作进程数 #error_log logs/error.log; # nginx错误日志
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; # nginx服务启动时候的pid events {
worker_connections 1024; # 每个进程允许最大连接数
} http {
include mime.types;
default_type application/octet-stream; # access_log日志展示格式
# $remote_addr:客户端地址
# $remote_user:客户端请求nginx认证的用户名,默认不开启认证模块,没有记录
# $time_local: 客户端请求的时间
# $request:客户端请求的请求头
# $status: 请求的状态码
# $body_bytes_sent: 服务端相应客户端body信息的大小
# $http_referer: 访问当前页面的上一级页面地址
# $http_user_agent: 客户端浏览器的agent
# $http_x_forwarded_for:请求所携带的http信息 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; server {
listen 80; # 监听前端打开的80端口
server_name localhost; # 代理前端访问的地址 charset utf-8; #access_log logs/host.access.log main; location / {
root html; # 需要代理的前端页面代码目录(包含index.html等文件的目录)
index index.html index.htm;
} location /test/ {
proxy_pass http://127.0.0.1:8000/test/; # 将前端的/test/请求转发到后端哪个地址
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }
# 静态资源文件
location /files/ {
root F:/nginx-1.12.2/nginx-1.12.2/;
autoindex on;
}
#error_page 404 /404.html; # redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
} # 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;
# }
#} }

(完)

最新文章

  1. Unit01: JAVA开发环境案例
  2. int unsigned实验
  3. 如何消除inline-block元素间间距问题(转)
  4. Codeforces Round #346 (Div. 2)E - New Reform(DFS + 好题)
  5. WebService学习总结(三)——使用JDK开发WebService
  6. yum源的修改
  7. PHP代码优化技巧大盘点
  8. C++中巧妙的位运算
  9. Tempdb对SQL Server性能的影响
  10. [Bullet3]创建世界(场景)及常见函数
  11. Effective Modern C++ Item 37:确保std::thread在销毁时是unjoinable的
  12. 浅析Thread类run()和start()的区别
  13. TempFile模块
  14. Linux运行firefox出错
  15. Educational Codeforces Round 63 (Rated for Div. 2) D. Beautiful Array 分类讨论连续递推dp
  16. html5 基础入门
  17. shell实现大批量word转码然后分析相关字段
  18. RN android真机调试找不到设备
  19. Vue2+VueRouter2+webpack 构建项目实战(二):目录以及文件结构
  20. select cast(round(12.5,2) as numeric(5,2))

热门文章

  1. Java如何安装JDK,配置环境变量。超级详细图及操作
  2. Vue入门教程 第二篇 (数据绑定与响应式)
  3. python编程基础之二十一
  4. python编程基础之五
  5. 2016 10月15日java的动手动脑
  6. [Vijos] 遭遇战
  7. 自学web前端达到什么水平,才能满足求职的标准?
  8. 实验吧之【拐弯抹角】(url伪静态)
  9. veil-Evasion免杀使用
  10. 修改配置文件application.properties