nginx学习记录
来源:互联网 发布:php数据传到html页面 编辑:程序博客网 时间:2024/05/21 11:30
搭建Http静态服务器环境
1.在 CentOS 上,可直接使用 yum
来安装 Nginx
yum install nginx -y
2.
外网用户访问服务器的 Web 服务由 Nginx 提供,Nginx 需要配置静态资源的路径信息才能通过 url 正确访问到服务器上的静态资源。
打开 Nginx 的默认配置文件 /etc/nginx/nginx.conf ,修改 Nginx 配置,将默认的
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 作为所有静态资源请求的根路径,如访问:
nginx -s reload
4.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>
6.
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://123.206.221.217/static/index.js
,将会去 /data/www/static/ 目录下去查找 index.js
。现在我们需要重启 Nginx 让新的配置生效,如:nginx -s reload
4.
重启后,现在我们应该已经可以使用我们的静态服务器了,现在让我们新建一个静态文件,查看服务是否运行正常。
首先让我们在 /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>
6.
现在访问 http://123.206.221.217/index.html 应该可以看到页面输出
到此,一个基于 Nginx 的静态服务器就搭建完成了,现在所有放在 /data/www 目录下的的静态资源都可以直接通过域名访问。
阅读全文
0 0
- nginx 实战学习记录
- nginx学习记录
- nginx学习记录
- 对nginx学习记录
- nginx学习记录
- Nginx 配置学习记录
- Nginx学习记录
- nginx学习记录01-安装nginx
- nginx 反向代理 学习记录
- Nginx日志记录Cookie 学习笔记
- nginx源码学习记录(一)
- Nginx安装学习使用详细记录
- nginx学习记录02-配置说明
- Nginx 记录
- nginx记录
- 专门为Nginx开个模块,记录最近的学习
- 最近学习的memcached+服务器编程+nginx博客地址记录
- nginx学习记录--安装和转发到tomcat
- 下载YouTube视频的网站和工具
- HDU 6069 Counting Divisors 多校联合第四场
- JSP页面 jquery发送post请求到 contrallor 接受JSON数据
- CSS盒模型
- 生成Webservice客户端的4种方法
- nginx学习记录
- 如何实现MySQL索引优化【转】
- Python持久化pickle
- js字符串的使用
- 搭建 SVN 环境
- sudo apt-get update更新错误
- 集合框架_对象数组、集合(Collection)、集合(List)总结
- Linux终端如何安装Tomcat 7
- Makefile文件