V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
通过以下 Referral 链接购买 DigitalOcean 主机,你将可以帮助 V2EX 持续发展
DigitalOcean - SSD Cloud Servers
yousurm
V2EX  ›  VPS

用VPS安装wordpress,打开域名一直显示404 not found,是什么原因造成的,如何解决?

  •  
  •   yousurm · 2013-06-25 23:01:24 +08:00 · 1489 次点击
    这是一个创建于 4171 天前的主题,其中的信息可能已经有所发展或是发生改变。
    wordpress的文件和配置都已经弄好,放在/root/domains/blog/public_html/ 下
    数据库和域名解析也准备就绪

    域名也已经指向/root/domains/blog/
    /root/vhost.sh的指令也执行过了

    但是目前打开sin.cityfall.com安装wordpress的时候,显示404 not found,请问该如何解决?
    33 条回复    1970-01-01 08:00:00 +08:00
    donald
        1
    donald  
       2013-06-25 23:04:14 +08:00
    你不是放在public_html下,域名也应该指向public_html下啊。
    AstroProfundis
        2
    AstroProfundis  
       2013-06-25 23:04:52 +08:00
    目测你放博客的地方和域名指向的地方不一样
    yousurm
        3
    yousurm  
    OP
       2013-06-25 23:07:43 +08:00
    @AstroProfundis @donald 已重新指向 还是不可以~
    donald
        4
    donald  
       2013-06-25 23:10:41 +08:00
    @yousurm 把你nginx的error log贴上来
    donald
        5
    donald  
       2013-06-25 23:11:50 +08:00
    @yousurm 最好还有部分的conf内容
    Ansonyi
        6
    Ansonyi  
       2013-06-25 23:13:30 +08:00
    Rewrite的问题?或者权限?
    yousurm
        7
    yousurm  
    OP
       2013-06-25 23:17:02 +08:00
    @Ansonyi 权限也已经修改成777
    yousurm
        8
    yousurm  
    OP
       2013-06-25 23:20:09 +08:00
    @donald
    是这个吗?


    #user nobody;
    worker_processes 1;

    #error_log logs/error.log;
    #error_log logs/error.log notice;
    #error_log logs/error.log info;

    #pid logs/nginx.pid;


    events {
    worker_connections 1024;
    }


    http {
    include mime.types;
    default_type application/octet-stream;

    #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 logs/access.log main;

    sendfile on;
    #tcp_nopush on;

    #keepalive_timeout 0;
    keepalive_timeout 65;

    #gzip on;

    server {
    listen 80;
    server_name localhost;

    #charset koi8-r;

    #access_log logs/host.access.log main;

    location / {
    root html;
    index index.html index.htm;
    }

    #error_page 404 /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    # proxy_pass http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    # root html;
    # fastcgi_pass 127.0.0.1:9000;
    # fastcgi_index index.php;
    # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
    # include fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    # deny all;
    #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    # listen 8000;
    # listen somename:8080;
    # server_name somename alias another.alias;

    # location / {
    # root html;
    # index index.html index.htm;
    # }
    #}


    # HTTPS server
    #
    #server {
    # listen 443;
    # server_name localhost;

    # ssl on;
    # ssl_certificate cert.pem;
    # ssl_certificate_key cert.key;

    # ssl_session_timeout 5m;

    # ssl_protocols SSLv2 SSLv3 TLSv1;
    # ssl_ciphers HIGH:!aNULL:!MD5;
    # ssl_prefer_server_ciphers on;

    # location / {
    # root html;
    # index index.html index.htm;
    # }
    #}

    }
    manoon
        9
    manoon  
       2013-06-25 23:43:46 +08:00
    一般的小博客。。。用apache多方便,整 nginx这么复杂做什么。
    @yousurm 你把errorlog注释掉了。。。
    yousurm
        10
    yousurm  
    OP
       2013-06-25 23:49:44 +08:00
    @manoon 搞不懂啊 第一次用VPS弄主机 Lnmp是别人帮我弄好的,目前想自己新建个博客 搞不明白了。errorlog不知道该如何去除注释 囧。。。。
    manoon
        11
    manoon  
       2013-06-25 23:54:20 +08:00   ❤️ 1
    想学习NGINX相关的东西,就踏踏实实把相关的文档看完。
    如果只想搭个博客的话。
    直接yum install httpd php mysql php-* mysql-* 然后简单的编辑一下配置文件,就足够了。
    iCodex
        12
    iCodex  
       2013-06-25 23:56:54 +08:00
    初学者建议用apache,nginx还是以后熟悉之后再说吧。
    donald
        13
    donald  
       2013-06-26 00:53:13 +08:00   ❤️ 1
    @yousurm 。。。你这个刚装上什么都没有配置啊。。。网上找点教程看一下吧,要改动的地方太多了
    itommy
        14
    itommy  
       2013-06-26 00:58:54 +08:00   ❤️ 2
    可以重来的话,LAMP 就好了,有很详细的 tutorial 在 digital ocean 的官网上

    https://www.digitalocean.com/community/articles/how-to-install-wordpress-on-ubuntu-12-04

    要是继续坚持 nginx 的话:

    https://www.digitalocean.com/community/articles/how-to-install-wordpress-with-nginx-on-ubuntu-12-04
    yousurm
        15
    yousurm  
    OP
       2013-06-26 08:13:55 +08:00
    @donald 这个VPS上之前已经有别人帮我安装好一个域名的博客。那意思是说,要新建网站的话,所有东西都要重新配置一遍是吗? 还有具体哪些东西是需要重新配置的?
    yousurm
        16
    yousurm  
    OP
       2013-06-26 08:14:24 +08:00
    @itommy 好的 我晚上研究一下~
    yousurm
        17
    yousurm  
    OP
       2013-06-26 08:15:40 +08:00
    @manoon @iCodex 单纯想配置一个网站呢~ 等网页端熟悉了 再考虑了解这些
    yexiaoxing
        18
    yexiaoxing  
       2013-06-26 08:16:04 +08:00 via Android
    用的是lnmp吧,看nginx下有没有vhost目录,贴出来
    yousurm
        19
    yousurm  
    OP
       2013-06-26 08:18:56 +08:00
    @yexiaoxing 嗯 是的 Vhost.sh是这样的:

    #!/bin/bash

    # Check if user is root
    if [ $(id -u) != "0" ]; then
    echo "Error: You must be root to run this script, use sudo sh $0"
    exit 1
    fi

    clear
    echo "========================================================================="
    echo "Add Virtual Host for LNMP V0.9 , Written by Licess "
    echo "========================================================================="
    echo "LNMP is a tool to auto-compile & install Nginx+MySQL+PHP on Linux "
    echo "This script is a tool to add virtual host for nginx "
    echo "For more information please visit http://www.lnmp.org/"
    echo ""
    echo "========================================================================="

    if [ "$1" != "--help" ]; then


    domain="www.lnmp.org"
    echo "Please input domain:"
    read -p "(Default domain: www.lnmp.org):" domain
    if [ "$domain" = "" ]; then
    domain="www.lnmp.org"
    fi
    if [ ! -f "/usr/local/nginx/conf/vhost/$domain.conf" ]; then
    echo "==========================="
    echo "domain=$domain"
    echo "==========================="
    else
    echo "==========================="
    echo "$domain is exist!"
    echo "==========================="
    fi

    echo "Do you want to add more domain name? (y/n)"
    read add_more_domainame

    if [ "$add_more_domainame" == 'y' ]; then

    echo "Type domainname,example(bbs.vpser.net forums.vpser.net luntan.vpser.net):"
    read moredomain
    echo "==========================="
    echo domain list="$moredomain"
    echo "==========================="
    moredomainame=" $moredomain"
    fi

    vhostdir="/home/wwwroot/$domain"
    echo "Please input the directory for the domain:$domain :"
    read -p "(Default directory: /home/wwwroot/$domain):" vhostdir
    if [ "$vhostdir" = "" ]; then
    vhostdir="/home/wwwroot/$domain"
    fi
    echo "==========================="
    echo Virtual Host Directory="$vhostdir"
    echo "==========================="

    echo "==========================="
    echo "Allow Rewrite rule? (y/n)"
    echo "==========================="
    read allow_rewrite

    if [ "$allow_rewrite" == 'n' ]; then
    rewrite="none"
    else
    rewrite="other"
    echo "Please input the rewrite of programme :"
    echo "wordpress,discuz,typecho,sablog,dabr rewrite was exist."
    read -p "(Default rewrite: other):" rewrite
    if [ "$rewrite" = "" ]; then
    rewrite="other"
    fi
    fi
    echo "==========================="
    echo You choose rewrite="$rewrite"
    echo "==========================="

    echo "==========================="
    echo "Allow access_log? (y/n)"
    echo "==========================="
    read access_log

    if [ "$access_log" == 'n' ]; then
    al="access_log off;"
    else
    echo "Type access_log name(Default access log file:$domain.log):"
    read al_name
    if [ "$al_name" = "" ]; then
    al_name="$domain"
    fi
    alf="log_format $al_name '\$remote_addr - \$remote_user [\$time_local] \"\$request\" '
    '\$status \$body_bytes_sent \"\$http_referer\" '
    '\"\$http_user_agent\" \$http_x_forwarded_for';"
    al="access_log /home/wwwlogs/$al_name.log $al_name;"
    echo "==========================="
    echo You access log file="$al_name.log"
    echo "==========================="
    fi

    get_char()
    {
    SAVEDSTTY=`stty -g`
    stty -echo
    stty cbreak
    dd if=/dev/tty bs=1 count=1 2> /dev/null
    stty -raw
    stty echo
    stty $SAVEDSTTY
    }
    echo ""
    echo "Press any key to start create virtul host..."
    char=`get_char`


    if [ ! -d /usr/local/nginx/conf/vhost ]; then
    mkdir /usr/local/nginx/conf/vhost
    fi

    echo "Create Virtul Host directory......"
    mkdir -p $vhostdir
    touch /home/wwwlogs/$al_name.log
    echo "set permissions of Virtual Host directory......"
    chmod -R 755 $vhostdir
    chown -R www:www $vhostdir

    if [ ! -f /usr/local/nginx/conf/$rewrite.conf ]; then
    echo "Create Virtul Host ReWrite file......"
    touch /usr/local/nginx/conf/$rewrite.conf
    echo "Create rewirte file successful,now you can add rewrite rule into /usr/local/nginx/conf/$rewrite.conf."
    else
    echo "You select the exist rewrite rule:/usr/local/nginx/conf/$rewrite.conf"
    fi

    cat >/usr/local/nginx/conf/vhost/$domain.conf<<eof
    $alf
    server
    {
    listen 80;
    server_name $domain$moredomainame;
    index index.html index.htm index.php default.html default.htm default.php;
    root $vhostdir;

    include $rewrite.conf;
    location ~ .*\.(php|php5)?$
    {
    try_files \$uri =404;
    fastcgi_pass unix:/tmp/php-cgi.sock;
    fastcgi_index index.php;
    include fcgi.conf;
    }

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
    expires 30d;
    }

    location ~ .*\.(js|css)?$
    {
    expires 12h;
    }

    $al
    }
    eof

    echo "Test Nginx configure file......"
    /usr/local/nginx/sbin/nginx -t
    echo ""
    echo "Restart Nginx......"
    /usr/local/nginx/sbin/nginx -s reload

    echo "========================================================================="
    echo "Add Virtual Host for LNMP V0.9 , Written by Licess "
    echo "========================================================================="
    echo "For more information please visit http://www.lnmp.org/"
    echo ""
    echo "Your domain:$domain"
    echo "Directory of $domain:$vhostdir"
    echo ""
    echo "========================================================================="
    fi
    yousurm
        20
    yousurm  
    OP
       2013-06-26 08:19:40 +08:00
    @yexiaoxing 之前别人帮我配置好,然后把原先的网站转移过来了。现在我想重新添加一个网站,用wordpress搭建。
    nVic
        21
    nVic  
       2013-06-26 08:35:07 +08:00 via iPad   ❤️ 1
    安装完成后,安装虚拟主机:
    /root/vhost.sh
    www.mydomainname.com+enter
    y+mydomainname.com+enter(带www和不带www的网址绑定同一虚拟主机)
    接下来选择添加伪静态规则。wordpress+enter
    m/y+enter

    lnmp环境简单配置完成。
    其中伪静态未设置,可以随时添加。
     
    安装wordpress:
    wget http://wordpress.org/latest.tar.gz   (下载wordpress最新版本)
    tar -zxvf latest.tar.gz  /home/wwwroot/www.mydomain.com/
    www.mydomain.com/phpmyadmin 选择数据库,点击新建数据库a_db,设定用户名user密码user,设定用户权限
     mv /var/www/wp-config-sample.php /var/www/wp-config.php

    nano /var/www/wp-config.php
    找到以下内容
    // ** MySQL settings – You can get this info from your web host ** //
    /** The name of the database for WordPress */
    define(‘DB_NAME’, ‘database_name_here’);
    /** MySQL database username */
    define(‘DB_USER’, ‘username_here’);
    /** MySQL database password */
    define(‘DB_PASSWORD’, ‘password_here’);
    /** MySQL hostname */
    define(‘DB_HOST’, ‘localhost’);
    改为
    // ** MySQL settings – You can get this info from your web host ** //
    /** The name of the database for WordPress */
    define(‘DB_NAME’, ‘a_db’);
    /** MySQL database username */
    define(‘DB_USER’, ‘user’);
    /** MySQL database password */
    define(‘DB_PASSWORD’, ‘user’);
    /** MySQL hostname */
    define(‘DB_HOST’, ‘localhost’);
                 5,chown -R www:www /home/wwwroot/www.mydomain.com/  改变权限
                  6,reboot,重启
    这样,输入www.mydomain.com/index.php就可以直接进入wordpress安装了。
    manhere
        22
    manhere  
       2013-06-26 08:37:39 +08:00
    军哥的lnmp网站目录位于: /home/wwwroot/domain/
    kennedy32
        23
    kennedy32  
       2013-06-26 08:57:14 +08:00 via Android
    lamp路过
    yexiaoxing
        24
    yexiaoxing  
       2013-06-26 09:00:03 +08:00 via Android
    @yousurm 你在脚本中输入的路径是什么,你就应该把文件放在哪里呀。
    msg7086
        25
    msg7086  
       2013-06-26 09:11:26 +08:00
    路人表示如果不用LNMP这种第三方解决方案的话,nginx配置起来是非常方便的,至少比apache方便太多了。
    hengzhang
        26
    hengzhang  
       2013-06-26 09:15:39 +08:00
    还是推荐用wdcp吧,linux vps中文控制面板。
    对于我这种对命令一窍不通的菜鸟来说,这种最实在。
    horsley
        27
    horsley  
       2013-06-26 09:32:42 +08:00
    军哥的lnmp
    新域名网站目录位于: /home/wwwroot/具体域名/
    IP访问根目录 : /home/wwwroot/

    不推荐wdcp 漏洞多 又加密非开源 不敢用
    AstroProfundis
        28
    AstroProfundis  
       2013-06-26 09:36:24 +08:00
    你贴的第一个nginx配置文件里面,location / 下面指定了 root html; 所以不对。
    另外第二个是生成虚拟主机的脚本不是虚拟主机的配置。
    你试试在第一个文件里面加上一行 include /usr/local/nginx/conf/vhost/*.conf; 加载 location / {...} 那段后面。
    66beta
        29
    66beta  
       2013-06-26 10:17:00 +08:00
    装ubuntu啊,一句话搞定 apt-get install lamp-server^
    b824379598
        30
    b824379598  
       2013-06-26 10:36:35 +08:00
    wdcp一键安装包搞定
    yylzcom
        31
    yylzcom  
       2013-06-26 14:46:54 +08:00
    推荐actgod的脚本,是lowendbox的脚本增强版,适用于debian系统
    像我这样的懒人可以轻松管理vps(当然肯定比不上GUI)
    qingting
        32
    qingting  
       2013-06-26 15:19:01 +08:00
    网站放在/root目录下, nginx或者php没有权限访问, 自然就是404了。
    建议更换目录, 并且添加用户www。 如果觉得操作麻烦,还是用lnmp包吧
    yousurm
        33
    yousurm  
    OP
       2013-06-26 23:07:04 +08:00
    @nVic 谢谢 我昨天也是用你这个方法,后来发现自定义目录的时候,把目录放到了一个之前未配置的文件夹里了 我用了默认的路径 已经成功 非常感谢!
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1185 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 23:11 · PVG 07:11 · LAX 15:11 · JFK 18:11
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.