Nginx static resource file cannot be accessed, 403 forbidden error, nginxforbidden
After installing the nginx server, I want to set the root directory of the website/root/www/
, Songinx
Ofnginx.conf
File Configuration
Open firstnginx.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 UTF-8; # access_log logs/host. access. log main; location/{root/www/; # Set the local index index.html index.htm;} # error_page 404/404 .html; # redirect server error pages to the static page/50x.html # error_page 500 502 50 3 504/50 x.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. htaccess files, if Apache's document root # concurs with nginx's one # location ~ /\. Ht {# deny all ;#}}}
After saving, restart the nginx service and the error 403 is displayed.
After online query, the permission is incorrect. Change the first line of nginx. conf.
Set#user nobody;
Changeuser root;
Save and restart the nginx service again. The access is successful.
If you do not want to use the root user to run the program, you cannot place the Directory/root/
Directory./home/www
And set the www permission to 777.