Nginx配置搭建静态网站
2017-07-02 14:19
549 查看
1 安装Nginx并启动(打开ip,看到测试网页)
2 配置静态服务器访问路径
外网用户访问服务器的 Web 服务由 Nginx 提供,Nginx 需要配置静态资源的路径信息才能通过 url 正确访问到服务器上的静态资源。
打开 Nginx 的默认配置文件 /etc/nginx/nginx.conf ,修改 Nginx 配置,将默认的 root /usr/share/nginx/html; 修改为: root /data/www;,如下:
3 配置文件将 /data/www/static 作为所有静态资源请求的根路径,如访问: http://119.29.232.198/static/index.js,将会去 /data/www/static/ 目录下去查找 index.js。现在我们需要重启 Nginx 让新的配置生效,如:
nginx -s reload
4
重启后,现在我们应该已经可以使用我们的静态服务器了,现在让我们新建一个静态文件,查看服务是否运行正常。
首先让我们在 /data 目录 下创建 www 目录,如:
mkdir -p /data/www
5
在 /data/www 目录下创建我们的第一个静态文件 index.html,并访问
2 配置静态服务器访问路径
外网用户访问服务器的 Web 服务由 Nginx 提供,Nginx 需要配置静态资源的路径信息才能通过 url 正确访问到服务器上的静态资源。
打开 Nginx 的默认配置文件 /etc/nginx/nginx.conf ,修改 Nginx 配置,将默认的 root /usr/share/nginx/html; 修改为: root /data/www;,如下:
user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; 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 { listen 80 default_server; listen [::]:80 default_server; server_name _; root /data/www; include /etc/nginx/default.d/*.conf; location / { } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } } }
3 配置文件将 /data/www/static 作为所有静态资源请求的根路径,如访问: http://119.29.232.198/static/index.js,将会去 /data/www/static/ 目录下去查找 index.js。现在我们需要重启 Nginx 让新的配置生效,如:
nginx -s reload
4
重启后,现在我们应该已经可以使用我们的静态服务器了,现在让我们新建一个静态文件,查看服务是否运行正常。
首先让我们在 /data 目录 下创建 www 目录,如:
mkdir -p /data/www
5
在 /data/www 目录下创建我们的第一个静态文件 index.html,并访问
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8"> <title>第一个静态文件</title> </head> <body> Hello world! </body> </html>
相关文章推荐
- Nginx 配置 SSL 证书 + 搭建 HTTPS 网站教程
- centos下linux运行asp网站搭建配置-mono+nginx
- Nginx搭建静态网站
- 基于CentOS搭建Nginx 静态网站
- Docker通过Nginx镜像快速搭建静态网站
- 实时监控、直播流、流媒体、视频网站开发方案流媒体服务器搭建及配置详解:使用nginx搭建rtmp直播、rtmp点播、,hls直播服务配置详解
- 搭建Nginx静态网站
- 搭建Nginx1.10.x静态网站(PC和Mobile)
- nginx配置1:借助Nginx搭建反向代理服务器与缓存静态文件
- Hexo+GitHub搭建静态博客平台(二)-配置网站及使用
- Nginx 配置 SSL 证书 + 搭建 HTTPS 网站教程
- [转] Nginx 配置 SSL 证书 + 搭建 HTTPS 网站教程
- 利用Docket使用nginx镜像快速搭建静态网站
- 实时监控、直播流、流媒体、视频网站开发方案流媒体服务器搭建及配置详解:使用nginx搭建rtmp直播、rtmp点播、,hls直播服务配置详解
- Nginx下让WordPress支持伪静态规则及网站下级目录配置伪静态教程
- [置顶] NGINX 配置 SSL 证书 搭建 HTTPS 网站
- nginx最简单的网站配置:单主机+静态文件
- Nginx 配置 SSL 证书 + 搭建 HTTPS 网站教程
- nginx搭建静态网站
- 使用Nginx搭建静态文件服务及配置PHP运行环境