V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
wjwgg
V2EX  ›  Linux

搭建了 LNMP 环境,但是访问一直 403 找不到原因所在了 有大神知道原因吗

  •  
  •   wjwgg · 2019-12-24 16:44:36 +08:00 · 5202 次点击
    这是一个创建于 1575 天前的主题,其中的信息可能已经有所发展或是发生改变。
    都是 YUM 安装的 NGINX PHP MYSQL 都配置好了 nginx 和 php 都是 root 用户运行的 目录权限也都有 777 了
    一点链接就会 403 下面是网站 http://47.244.220.209
    下面附上 nginx.conf 配置
    user root;
    worker_processes auto;
    error_log /var/log/nginx/error.log;
    pid /run/nginx.pid;

    # Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
    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;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name _;
    index index.html index.htm index.php;
    root /usr/share/nginx/html;

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location / {
    }
    location ~ \.php$ {
    root html;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    }
    error_page 404 /404.html;
    location = /40x.html {
    }

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    }
    }
    13 条回复    2019-12-25 07:19:34 +08:00
    BB0923
        1
    BB0923  
       2019-12-24 16:53:37 +08:00
    访问了一下,没问题啊
    BB0923
        2
    BB0923  
       2019-12-24 16:54:26 +08:00
    数据库密码看看对了没有
    s527332935
        3
    s527332935  
       2019-12-24 16:56:25 +08:00
    提示 404 啊
    helionzzz
        4
    helionzzz  
       2019-12-24 16:57:29 +08:00
    访问了下 没问题啊
    wjwgg
        5
    wjwgg  
    OP
       2019-12-24 17:03:57 +08:00
    @BB0923 @helionzzz 随便点个链接就 404
    helionzzz
        6
    helionzzz  
       2019-12-24 17:05:48 +08:00
    @wjwgg 404 是没有生成静态页面吧。
    batyu
        7
    batyu  
       2019-12-24 17:07:10 +08:00
    看看 rewrite 规则吧,URL 明显有问题
    elevioux
        8
    elevioux  
       2019-12-24 17:11:37 +08:00
    伪静态( url 美化)没做吧

    在 server 节点上加上

    ```
    location / {
    try_files $uri $uri/ /index.php?$query_string;
    }
    ```

    试一下。

    上面那个是 laravel 的规则,不过应该也可以用的。仔细看一下 typecho 的部署文档,应该有提到的。
    wjwgg
        9
    wjwgg  
    OP
       2019-12-24 17:19:27 +08:00
    @elevioux OK 了 感谢。是伪静态没做 @batyu 谢谢 @BB0923 和数据库没关系 要数据库有问题 在线安装的时候就报错了
    luhe
        10
    luhe  
       2019-12-24 18:07:46 +08:00
    解决了的话,那么可以发个 Typecho 主题推荐了 https://blog.luhe.xyz/archives/44/
    wjwgg
        11
    wjwgg  
    OP
       2019-12-24 20:07:57 +08:00
    @luhe 哈哈 我用的就是友人的
    ysc3839
        12
    ysc3839  
       2019-12-25 01:51:00 +08:00 via Android
    @elevioux Typecho 的文档多年未更新,最后更新时间是 2013 年了 http://docs.typecho.org/faq

    而且还犯了一个 nginx 常见错误——用 if -e 和 rewrite 而不用 try_files。
    try_files 理论上性能比 rewrite 更好的,因为不需要进行正则匹配。
    对于“如果文件不存在,则请求 /index.php”这种用途应该使用 try_files。
    rewrite 则应该用于复杂的路径处理,比如说把 /a/b.html 映射到 /index.php?x=a&y=b 这种情况。
    wnpllrzodiac
        13
    wnpllrzodiac  
       2019-12-25 07:19:34 +08:00 via Android
    777 一看就小白
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1025 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 19:41 · PVG 03:41 · LAX 12:41 · JFK 15:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.