[英]Nginx 403 Forbidden when running PHP
注意:我在任何地方都沒有得到我的答案這就是我做這個的原因
我的 nginx.conf 文件:
#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 index.php;
}
#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 C:/nginx/html/$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 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
我也跑了
php-cgi.exe -b 127.0.0.1:9000
在我的 C:\PHP 的命令提示符中
我得到的錯誤是
403 禁止 nginx/1.19.7
在本地主機中。
我沒有代理,我真的不知道錯誤是什么我注意到有一個錯誤文件所以這里是該文件的內容:
2021/03/08 07:13:46 [emerg] 17544#7752: bind() to 0.0.0.0:80 failed (10013: An attempt was made to access a socket in a way forbidden by its access permissions)
2021/03/08 07:14:04 [emerg] 1160#19796: bind() to 0.0.0.0:80 failed (10013: An attempt was made to access a socket in a way forbidden by its access permissions)
2021/03/08 07:14:15 [emerg] 15840#20192: bind() to 0.0.0.0:80 failed (10013: An attempt was made to access a socket in a way forbidden by its access permissions)
2021/03/08 07:17:55 [error] 17248#19796: *9 CreateFile() "C:\nginx/html/robots.txt" failed (2: The system cannot find the file specified), client: 127.0.0.1, server: localhost, request: "GET /robots.txt?448659 HTTP/1.1", host: "localhost"
2021/03/08 07:25:13 [error] 17248#19796: *41 CreateFile() "C:\nginx/html/phpmyadmin" failed (2: The system cannot find the file specified), client: 127.0.0.1, server: localhost, request: "GET /phpmyadmin HTTP/1.1", host: "localhost"
2021/03/08 07:26:02 [error] 17248#19796: *41 directory index of "C:\nginx/html/Facebook/" is forbidden, client: 127.0.0.1, server: localhost, request: "GET /Facebook/ HTTP/1.1", host: "localhost"
2021/03/08 07:26:07 [error] 17248#19796: *48 CreateFile() "C:\nginx/html/robots.txt" failed (2: The system cannot find the file specified), client: 127.0.0.1, server: localhost, request: "GET /robots.txt?448659 HTTP/1.1", host: "localhost"
2021/03/08 07:26:48 [error] 17248#19796: *49 CreateFile() "C:\nginx/html/favicon.ico" failed (2: The system cannot find the file specified), client: 127.0.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "127.0.0.1", referrer: "http://127.0.0.1/"
2021/03/08 07:26:53 [error] 17248#19796: *49 directory index of "C:\nginx/html/Facebook/" is forbidden, client: 127.0.0.1, server: localhost, request: "GET /Facebook/ HTTP/1.1", host: "127.0.0.1"
2021/03/08 07:31:00 [error] 17248#19796: *70 directory index of "C:\nginx/html/" is forbidden, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost"
2021/03/08 07:31:00 [error] 17248#19796: *70 CreateFile() "C:\nginx/html/favicon.ico" failed (2: The system cannot find the file specified), client: 127.0.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "localhost", referrer: "http://localhost/"
2021/03/08 07:31:42 [error] 17248#19796: *70 directory index of "C:\nginx/html/" is forbidden, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost"
2021/03/08 07:31:43 [error] 17248#19796: *70 directory index of "C:\nginx/html/" is forbidden, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost"
2021/03/08 07:31:43 [error] 17248#19796: *70 directory index of "C:\nginx/html/" is forbidden, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost"
2021/03/08 07:32:24 [error] 17248#19796: *70 directory index of "C:\nginx/html/" is forbidden, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost"
2021/03/08 07:32:27 [error] 17248#19796: *70 directory index of "C:\nginx/html/" is forbidden, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost"
2021/03/08 07:32:28 [error] 17248#19796: *70 directory index of "C:\nginx/html/" is forbidden, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost"
2021/03/08 07:32:28 [error] 17248#19796: *70 directory index of "C:\nginx/html/" is forbidden, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost"
2021/03/08 07:32:29 [error] 17248#19796: *70 directory index of "C:\nginx/html/" is forbidden, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost"
2021/03/08 07:34:07 [error] 17248#19796: *89 directory index of "C:\nginx/html/" is forbidden, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost"
2021/03/08 07:35:52 [error] 17248#19796: *94 directory index of "C:\nginx/html/" is forbidden, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost"
2021/03/08 07:35:52 [error] 17248#19796: *94 directory index of "C:\nginx/html/" is forbidden, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost"
2021/03/08 07:35:53 [error] 17248#19796: *94 directory index of "C:\nginx/html/" is forbidden, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost"
2021/03/08 07:35:53 [error] 17248#19796: *94 directory index of "C:\nginx/html/" is forbidden, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost"
2021/03/08 07:35:53 [error] 17248#19796: *94 directory index of "C:\nginx/html/" is forbidden, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost"
2021/03/08 07:35:54 [error] 17248#19796: *94 directory index of "C:\nginx/html/" is forbidden, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost"
2021/03/08 07:37:29 [error] 17248#19796: *111 directory index of "C:\nginx/html/" is forbidden, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost"
2021/03/08 07:37:29 [error] 17248#19796: *111 CreateFile() "C:\nginx/html/favicon.ico" failed (2: The system cannot find the file specified), client: 127.0.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "localhost", referrer: "http://localhost/"
netsh http add iplisten ipaddress=:: 面臨類似問題。 在命令提示符下運行上述命令。 這應該會釋放端口 80,然后您就可以運行 nginx。
說明:netsh http命令用於查詢和配置HTTP.sys的設置和參數。
add iplisten:在IP監聽列表中增加一個新的IP地址,不包括端口號。 “::”表示任何 IPv6 地址。
有關更多 netsh http 命令,請參閱 netsh http 命令文檔。
並在不同的瀏覽器中刷新頁面
service nginx restart
或者
service nginx stop
service nginx start
檢查NGINX的狀態
service nginx status
如果問題仍然存在,請對項目進行完整備份。
卸載 NGINX 服務器
apt remove nginx
apt autoremove
apt install nginx
刪除服務器時,請確保僅卸載服務器。 這樣您就不會遇到其他服務器附加組件的問題。
研究
https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.