html css静态网页实例(使用nginx部署前端html等静态页面)

一、前言

最近想要部署一个纯前端的静态页面,项目的内容很简单,也就是一些简单的html、css、js、jpg、mp3等静态资源,不涉及后端开发。

之前一直都是使用Tomcat来部署项目的,因为涉及后端接口等方面的内容,这次再用它来部署纯前端的东西,显得大材小用,过于笨重。

此时,使用nginx,便是最合适的选择了,轻量、简单、灵活。

二、nginx安装下载

我的服务器是在腾讯云上买的,操作系统是Centos,Linux中的一种。

html网页制作实例

安装使用自带的命令yum即可

yum install nginx三、nginx配置

安装完,nginx的相关目录就都有了,最重要的一个配置文件nginx.conf在于

/etc/nginx/nginx.conf

我们一般在这里配置完项目的相关信息的配置,如访问权限、访问端口、访问机器、访问项目、访问文件等:

#1.注意user使用root,以便轻松访问任何文件 user root; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; # Load dynamic modules. See /usr/share/doc/nginx/README.dynamic. include /usr/share/nginx/modules/*.conf; events { worker_connections 1024; } 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 /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; include /etc/nginx/conf.d/*.conf; server { #2.这里监听我们常用的80端口 listen 80; #3.这里配置机器地址,一般是本机localhost server_name localhost; #4.这里配置项目根路径 root /root/love; #5.这里配置项目的访问页面 index index.html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { } error_page 404 /404.html; location = /404.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } } }四、nginx命令

配置完毕,我们便可启动nginx,完成部署,如果期间修改配置文件,我们则在reload下即可,下面罗列下几个常用的命令:

#启动nginx systemctl start nginx.service #停止nginx systemctl stop nginx.service #重新加载nginx配置 systemctl reload nginx.service #查看nginx状态 systemctl status nginx.service

您可以还会对下面的文章感兴趣

最新评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

使用微信扫描二维码后

点击右上角发送给好友