Ngnix搭建静态网页和安装wordpress

使用nginx搭建wordpress和静态网站。以下操作均实在ubuntu1604完成。

安装nginx

apt install nginx

验证安装是否完成。在浏览器打开127.0.0.1,能够看到nginx启动则代表完成。

新建自己的静态文件index.html

index.html

<html>
<haed>
</head>
  <body>
    <p>my first page</p>
  </body>
</html>

创建index.html的配置文件demo.conf

demo.conf

server {

   listen 80;                 #监听端口
   server_name localhost;     #域名解析
   root /home/demo;   #html所在目录

   location / {
      index index.html;       #html的名字
   }
}

移动配置文件到/etc/nginx/conf.d目录下

能够配置nginx的文件有三个地方,分别是:

  1. /etc/nginx/nginx.conf
  2. /etc/nginx/conf.d
  3. /etc/nginx/sites-enabled

其中/etc/nginx/nginx.conf 为主配置文件,在nginx读取配置文件时,首先读取nginx.conf,然后再读取/etc/nginx/conf.d中以conf结尾的文件,最后读取/etc/nginx/sites-enabled 链接的文件。所以这里选择第二种方式,新建demo.conf文件放在/etc/nginx/conf.d目录下。

重新加载nginx配置文件

nginx -s reload

安装wordperss


WordPress是使用PHP语言开发的博客平台,用户可以在支持PHP和MySQL数据库的服务器上架设属于自己的网站

安装mysql数据

apt install mysql-server

安装php

apt install php7.0 
apt install libapache2-mod-php7.0 
apt install php7.0-mysql

下载wordpress

wget  https://cn.wordpress.org/latest-zh_CN.tar.gz

解压wordpress

tar zvxf latest-zh-CN.tar.gz

创建数据库wordpress

create database wordpress

创建wordpress的配置文件

cp wp-config-sample.php wp-config.php

修改wordpress的配置文件

复制wordpress到/var/www文件夹

cp -r wordpress  /var/www/

新增nginx配置

/etc/nginx/conf.d/目录下新增wordpress.conf配置文件,同时删除上面的demo.conf配置文件
wordpress.conf

server {

     listen 80;
     listen [::]:80;
     root /var/www/wordpress;
     index index.html index.php index.nginx-debian.html;

     server_name localhost;

     location / {
        try_files $uri $uri/ =404;
     }
     
     location ~ \.php$ {

         include snippets/fastcgi-php.conf;
         fastcgi_pass unix:/run/php/php7.0-fpm.sock;
     }

}

重新加载配置文件

nginx -s reload

访问localhost安装wordpress

posted @ 2020-06-11 18:16  金色旭光  阅读(1684)  评论(0编辑  收藏  举报