403error (Laravel + Nginx + Apache) CentOS 8
Posted
技术标签:
【中文标题】403error (Laravel + Nginx + Apache) CentOS 8【英文标题】: 【发布时间】:2020-12-31 20:04:49 【问题描述】:我正在尝试将站点配置为使用 nginx 和 Apache。当我尝试访问该站点时,我收到了 403 错误。
在文件 /etc/httpd/conf/httpd.conf 我设置了默认端口 8089(因为 8080 已经很忙了):
Listen 127.0.0.1:8089
接下来,我为 Apache 创建一个配置 (/etc/httpd/conf.d/site.conf):
<VirtualHost 127.0.0.1:8089>
ServerName site.com
ServerAlias www.site.com
DocumentRoot "/usr/share/site/public"
ErrorLog /var/log/httpd/error.log
CustomLog /var/log/httpd/access.log combined
<Directory "/usr/share/site/public">
Require all granted
AllowOverride all
</Directory>
</VirtualHost>
最后,我为 Nginx 创建了一个配置(/etc/nginx/conf.d/site.conf):
server
listen 80;
server_name site.com www.site.com;
root /usr/share/site/public;
charset utf-8;
gzip on;
gzip_types
text/css
application/javascript
text/javascript
application/x-javascript
image/svg+xml
text/plain
text/xsd
text/xsl
text/xml
image/x-icon;
location /
try_files $uri $uri/ /index.php?$query_string;
location ~ \.php
proxy_pass http://localhost:8089;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
location ~ /\.ht
deny all;
可能是什么问题?
【问题讨论】:
欢迎来到 SO.. 你得到哪个端口403 error
?
【参考方案1】:
美好的一天!
通过 laravel 参考链接 https://laravel.com/docs/7.x/deployment 尝试这个原始配置
server
listen 80;
server_name site.com www.site.com;
root /usr/share/site/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
gzip on;
gzip_types
text/css
application/javascript
text/javascript
application/x-javascript
image/svg+xml
text/plain
text/xsd
text/xsl
text/xml
image/x-icon;
location /
try_files $uri $uri/ /index.php?$query_string;
location = /favicon.ico access_log off; log_not_found off;
location = /robots.txt access_log off; log_not_found off;
error_page 404 /index.php;
location ~ \.php$
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
location ~ /\.(?!well-known).*
deny all;
注意:
fastcgi_pass
你需要根据你的版本更改phpversion-fpm.sock;
【讨论】:
以上是关于403error (Laravel + Nginx + Apache) CentOS 8的主要内容,如果未能解决你的问题,请参考以下文章
403 Forbidden on nginx/1.4.6 (Ubuntu) - Laravel
如何使用 ajax 解决 Laravel Post Error 403?