window nginx 简单搭建服务器访问静态资源

摘要:
nginx命令:启动:startnginx停止:nginx-sstop||nginx-squit注:stop是快速停止nginx,可能并不保存相关信息;quit是完整有序的停止nginx,并保存相关信息。

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)

window nginx 简单搭建服务器访问静态资源第1张

解压之后的文件目录:

window nginx 简单搭建服务器访问静态资源第2张

二:运行nginx

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

启动nginx: start nginx

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

window nginx 简单搭建服务器访问静态资源第3张

如上图启动成功;

三:配置自己个服务端口

打开: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       443ssl;
    #    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目录下的文件

window nginx 简单搭建服务器访问静态资源第4张

这样简单的,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 简单搭建服务器访问静态资源》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇android的activity被杀死后如何重启mysql修改definer方法下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

【Docker】Docker介绍安装和使用

一.docker简介: docker是容器技术的一个代表,而容器技术是将程序打包和隔离的一种技术,其实它并不是一个新技术,之前在linux内核中早已存在,真正被大众所用所了解是因为docker的出现。docker之所以流行起来,是因为解决了一些计算机领域的痛点,它解决了软件包装的问题,保证开发与运维及测试环境的一致。docker可以将任何应用以轻量级容器的...

MAMP、wordpress安装

MAMP、Wordpress 一、MAMP   1、简介 1.1、MAMP:本地服务器环境的OS X软件(windows用的是WAMP,原理差不多) 1.2、Apache、MySQL、PHP、Postfix等服务器软件,如果安装了MAMP,等同于全部安装了 1.3、可以集中管理和调整运行环境:PHP多版本的切换、imagemagick图形处理工具、动态...

WebSocket入门及使用指南

最近在一个项目中,需要使用到websocket,于是就花了一点时间来熟悉websocket并总结写篇blog。 为何使用websocket 在浏览器与服务器通信间,传统的 HTTP 请求在某些场景下并不理想,比如实时聊天、实时性的小游戏等等, 其面临主要两个缺点: 无法做到消息的「实时性」; 服务端无法主动推送信息; 其基于 HTTP 的主要解决方案...

使用filebeat 收集日志到logstash 收集日志redis再到logstash到es

大型场合的工作流程图 filebeat -->logstash ---> redis ---> logstash --->es 工作环境: 需要两台logstash, 安装jdk8 [root@es-web1]# apt install openjdk-8-jdk -y 这里已经安装filebeat 配置filebeat(这里的...

arm64平台 Kubernetes 及 Harbor 离线部署方案

前言 随着国产化浪潮的兴起,部分企业及部门开始采用国产服务器,使用国产操作系统。本文针对国产服务器(长城)及国产操作系统(麒麟)实现离线部署 Kubernetes,相关离线程序包、配置文件、安装说明文档将在文中给出。 安装的组件如下: 程序包 版本 docker-ce 19.03.14 kubeadm、kubelet、kubectl v1.1...

如何让您的php也支持pthreads多线程

  我们常常会碰到这样一种情况,开发环境在windows下开发,而生产环境确是linux。windows下能正常运行,上传到linux后却无法好好地玩耍了。然后开始了一轮尼玛式的疯狂的查找原因,最后发现是服务器环境问题。这时只能默默地爆一句shit。最近在用php多线程开发一个小功能也碰到类似的问题,在此记录一下。   1、查找资料发现php5.3或以上,...