nginx---安装配置,访问静态网页

  1. 安装 nginx。注意,这种方式最简单,但无法添加第三方库。
$ yum install -y nginx
  1. 编写静态网页。
$ mkdir /data/web
$ vim index.html

<html>
    <head>
        <title>Example</title>
    </head>
    <body>
        Hello World
    </body>
</html>
  1. 在 /etc/nginx/nginx.conf 中添加 server,以访问静态网页。
server {
        listen       8080;       # 监听端口            
        server_name  localhost;  # 指定 ip 地址或者域名,多个配置之间用空格分隔
        root         /data/web;  # 站点目录            
        index        index.html; # 用户访问 web 网站时的全局首页

        location / {                 # 表示匹配访问根目录
                root    /data/web;   # 用于指定访问根目录时,访问虚拟主机的web目录
                index   index.html;  # 在不指定访问具体资源时,默认展示的资源文件列表
        }
  1. 启动 nginx
 $ systemctl start nginx

或者

$ nginx -c /etc/nginx/nginx.conf
$ ps -ef | grep nginx
root      9386     1  0 15:48 ?        00:00:00 nginx: master process nginx -c /etc/nginx/nginx.conf
nginx     9387  9386  0 15:48 ?        00:00:00 nginx: worker process
root      9402  7089  0 15:48 pts/0    00:00:00 grep --color=auto nginx
  1. 访问静态网页。
$ curl http://localhost:8080/
<html>
    <head>
        <title>Example</title>
    </head>
    <body>
        Hello World
    </body>
</html>

不过,为什么是这个样子?

在浏览器中访问就正常了很多
在这里插入图片描述

停止 nginx

$ systemctl stop nginx

或者

$ ps -ef | grep nginx
root      9386     1  0 15:48 ?        00:00:00 nginx: master process nginx -c /etc/nginx/nginx.conf
nginx     9387  9386  0 15:48 ?        00:00:00 nginx: worker process
root     10415  7089  0 15:58 pts/0    00:00:00 grep --color=auto nginx
$ kill 9386
[root@VM_133_121_centos nginx]# kill 9387
$ ps -ef | grep nginx
root     10701  7089  0 16:01 pts/0    00:00:00 grep --color=auto nginx

参考
Nginx安装及配置详解. https://www.cnblogs.com/fengff/p/8892590.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值