nginx命令:

启动: start nginx

停止:nginx -s stop ||  nginx -s quit

    注:stop是快速停止nginx,可能并不保存相关信息;quit是完整有序的停止nginx,并保存相关信息。

查看版本:nginx -v

重载配置:nginx -s reload

检查语法:nginx -t

步骤:

一:安装window (我目前使用的系统是win7)

 官网下载地址: https://nginx.org/en/download.html 如下图点击windows下载解压:(我安装版本:nginx-1.14.2)

解压之后的文件目录:

二:运行nginx

  在当前目录中打开cmd,快捷键方式:ctrl+shift -->鼠标右键---》在此处打开命令窗口

  启动nginx: start nginx

  在浏览地址栏输入:localhost 就会启动nginx默认html页面  ||  在cmd输入ipconfig获取当前使用电脑的ip地址

如上图启动成功;

三:配置自己个服务端口

  打开:nginx-1.14.2/conf/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;
} 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"'; #access_log logs/access.log main; sendfile on;
#tcp_nopush on; #keepalive_timeout 0;
keepalive_timeout 65; #gzip on; server {
listen 9000;//我修改过,防止和我启动其他服务发生冲突 这样我在启动nginx,打开默认页面url:localhost:9000
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / {
root html;
index index.html index.htm;
} #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;
#}
}
server { #这里是我自己配置服务端口
listen 8081;
server_name resouce;
root D:/book/resouces; #访问文件根目录
autoindex on; #是否浏览文件下的列表
location / { #是否允许跨域
add_header Access-Control-Allow-Origin *;
}
add_header Cache-Control "no-cache,must-revalidate";# 是否缓存
} # 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;
# }
#} }

上面listen:8081就是我自己配置服务器端口,只要启动nginx 我就可以通过localhost:8081访问我resouce目录下的文件

这样简单的,nginx 静态资源服务器就搭建成功了;

以下是我遇到的问题:

 ①修改完配置之后,我nginx -s reload报错:

[错误]|nginx: [error] invalid PID number "" in "/usr/local/nginx-1.12.2/nginx_my.pid"

  解决方案:检查nginx是否在启动(打开页面查看是否可以打开 || 使用命令 nginx -s reopen || 查看电脑进程是否存在 nginx 等等),确定启动之后再nginx -s reload;

  原因:nginx -s reload 仅告诉正在运行的nginx进程重新加载其配置,停止之后,没有正在运行的nginx进程发送信号,才会报错,找不到nginx_my.pid中的PID

  参考页面:https://blog.csdn.net/qq_28296925/article/details/80416552

比较简单,只是作为一个简单的小记。

window nginx 简单搭建服务器访问静态资源的更多相关文章

  1. web站点优化之使用tengine搭建静态资源服务器,静态资源合并加载案例剖析

    在一个项目还是单体架构的时候,所有的js,css,image都会在一个web网站上,看起来并没有什么问题,比如下面这样: 但是当web网站流量起来的时候,这个单体架构必须要进行横向扩展,而在原来的架构 ...

  2. nodejs 构建本地web测试服务器 以及 解决访问静态资源的问题!

    直接打开html文件,是以file:///方式打开的,这种方式很多时候会遇到跨域的问题,因此我们一般会搭建一个简易的本地服务器,来运行测试页面. 一.构建静态服务器 1.使用express模块 建立个 ...

  3. Spring Mvc Web 配置拦截规则与访问静态资源 (三)

    拦截规则配置 1. *.do <!-- Processes application requests --> <servlet> <servlet-name>app ...

  4. django 不能访问静态资源的解决办法

    最近在中文win10下使用python的django搭建web测试服务器,发现一个诡异的现象,正常配置好django的模型,视图和模板, 1.setting.py内容如下: ""& ...

  5. springboot 2.X 在访问静态资源的的时候出现404的问题

    通过idea快速搭建一个springboot项目: springboot版本2.1.6 在网上看的资料,springboot静态资源访问如下: "classpath:/META‐INF/re ...

  6. idea中JSP页面不能访问静态资源(图片,js,css)

    必须配置SpringMvc对访问静态资源的支持,idea默认就是在main/webapp 下的文件路径,要在web-info同级的resource文件下放置,JSP中 ${pageContext.re ...

  7. 访问静态资源有问题(配置url-pattern 用"/")(两种静态资源处理)

    发起的请求是由哪些服务器程序处理的 http://localhost:8080/ch05_url_pattern/index.jsp: tomcat(jsp会转为servlet) http://loc ...

  8. spring访问静态资源出错,No mapping found for HTTP request with URI xxx/resources/js/jquery.min.js...

    问题:spring访问静态资源出错,No mapping found for HTTP request with URI xxx/resources/js/jquery.min.js... web.x ...

  9. SpringMVC访问静态资源的三种方式(转)

    本文转自:http://www.iigrowing.cn/springmvc_fang_wen_jing_tai_zi_yuan_de_san_zhong_fang_shi.html 如何你的Disp ...

随机推荐

  1. linux文本编辑工具

    文本编辑工具VIM vim 主要有三种工作模式,分别是命令模式.插入模式和编辑模式,输入 vim 文件名 我们可以进入命令模式,输入字符 i或者a或者o我们可以进入插入模式,进入插入模式之后我们可以进 ...

  2. laravel 实现详情分页

    选择合适的PHP框架及前端框架布局页面(10分) 首先展示出分类列表,每个分类下只显示3条信息,无需分页 (30分) 在列表页 点击文章标题进入详细页面,对应的文章点击量+1(30分) 在详细页面点击 ...

  3. Java入土---Java运行机制及IDEA的安装使用

    Java运行机制及IDEA的安装使用 java程序运行机制 计算机高级语言分为编译型语言跟解释型语言,而java同时具有两者的特点. 可能对于新手来说,什么是编译,什么是解释; 简单来说,编译就是将代 ...

  4. 使用vscode Container开发调试envoy

    由于我最近在研究 envoy 这个项目,这是个cpp的项目,对于我这种cpp新人来说还是比较有压力的,感觉处处都是坑,开个引导文章记录一下. 如果要研究 envoy 项目源码,那肯定是需要代码跳转的, ...

  5. -std=c++11 编译器设置

    range-based 'for' loops are not allowed in C++98 mode

  6. MySQL面试题--常见的四种隔离级别

    什么是事务 事务是应用程序中一系列严密的操作,所有操作必须成功完成,否则在每个操作中所作的所有更改都会被撤消.也就是事务具有原子性,一个事务中的一系列的操作要么全部成功,要么一个都不做. 事务的结束有 ...

  7. 什么是Spring的依赖注入?

    依赖注入,是IOC的一个方面,是个通常的概念,它有多种解释.这概念是说你不用创建对象,而只需要描述它如何被创建.你不在代码里直接组装你的组件和服务,但是要在配置文件里描述哪些组件需要哪些服务,之后一个 ...

  8. Spring支持的事务管理类型?

    Spring支持两种类型的事务管理: 编程式事务管理 :这意味你通过编程的方式管理事务,给你带来极大的灵活性,但是难维护. 声明式事务管理: 这意味着你可以将业务代码和事务管理分离,你只需用注解和XM ...

  9. Spring框架中有哪些不同类型的事件?

      Spring 提供了以下5种标准的事件: (1)上下文更新事件(ContextRefreshedEvent):在调用ConfigurableApplicationContext 接口中的refre ...

  10. Redis ZSet Type

    Redis有序集合的操作命令和对应的api如下: zadd [zset] sco 'value' JedisAPI:public Long zadd(final String key, final d ...