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

2019-12-24 16:44:36 +08:00
 wjwgg
都是 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 {
}
}
5221 次点击
所在节点    Linux
13 条回复
BB0923
2019-12-24 16:53:37 +08:00
访问了一下,没问题啊
BB0923
2019-12-24 16:54:26 +08:00
数据库密码看看对了没有
s527332935
2019-12-24 16:56:25 +08:00
提示 404 啊
helionzzz
2019-12-24 16:57:29 +08:00
访问了下 没问题啊
wjwgg
2019-12-24 17:03:57 +08:00
@BB0923 @helionzzz 随便点个链接就 404
helionzzz
2019-12-24 17:05:48 +08:00
@wjwgg 404 是没有生成静态页面吧。
batyu
2019-12-24 17:07:10 +08:00
看看 rewrite 规则吧,URL 明显有问题
elevioux
2019-12-24 17:11:37 +08:00
伪静态( url 美化)没做吧

在 server 节点上加上

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

试一下。

上面那个是 laravel 的规则,不过应该也可以用的。仔细看一下 typecho 的部署文档,应该有提到的。
wjwgg
2019-12-24 17:19:27 +08:00
@elevioux OK 了 感谢。是伪静态没做 @batyu 谢谢 @BB0923 和数据库没关系 要数据库有问题 在线安装的时候就报错了
luhe
2019-12-24 18:07:46 +08:00
解决了的话,那么可以发个 Typecho 主题推荐了 https://blog.luhe.xyz/archives/44/
wjwgg
2019-12-24 20:07:57 +08:00
@luhe 哈哈 我用的就是友人的
ysc3839
2019-12-25 01:51:00 +08:00
@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
2019-12-25 07:19:34 +08:00
777 一看就小白

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/631920

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX