首页 > Web开发 > 详细

Ngnix搭建静态网页和安装wordpress

时间:2020-06-11 18:53:32      阅读:35      评论:0      收藏:0      [点我收藏+]

技术分享图片

使用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目录下。

技术分享图片

安装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

技术分享图片

Ngnix搭建静态网页和安装wordpress

原文:https://www.cnblogs.com/goldsunshine/p/13091536.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!