博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
nginx 配置 默认网站根目录(权限问题导致403 Forbidden错误的解决方法)
阅读量:7058 次
发布时间:2019-06-28

本文共 2232 字,大约阅读时间需要 7 分钟。

在安装 nginx 服务器后,我想把网站的根目录设置为 /root/www/ ,于是对 nginxnginx.conf 文件进行配置

先打开 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 utf-8;            #access_log  logs/host.access.log  main;            location / {            root   /root/www/;          ## 设置的地方            index  index.html index.htm;        }                #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  /scripts$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;            #}        }}

保存后,重启 nginx 服务,然后出现了 403 错误

网上查询后说是权限问题,更改 nginx.conf 的第一行

#user nobody; 改为 user root;

保存,再次重启 nginx 服务,访问成功

图片描述

如果不想使用root用户运行,就不能把目录放在 /root/ 目录下了,可以选择放在 /home/www 下,并设置 www 的权限 777,同样可以访问成功。

图片描述

转载地址:http://nmgol.baihongyu.com/

你可能感兴趣的文章
用了一天的时间,linux下expect实现ssh自动登录服务器记,鄙视下网上各种抄来抄去残段子...
查看>>
青岛市李沧区搭建人才大数据平台
查看>>
Linux下自动化监控内存、存储空间!
查看>>
iOS 7 表视图顶部空白解决
查看>>
中科院院士姚期智:我们已经来到量子时代的最后一里路
查看>>
“前.NET Core时代”如何实现跨平台代码重用 ——程序集重用
查看>>
一哄而起云计算(透视)
查看>>
如何实现对上下文(Context)数据的统一管理 [提供源代码下载]
查看>>
RvmTranslator Translate RVM to 3D PDF
查看>>
New Release: patterns & practices App Arch Guide 2.0 Beta 1
查看>>
《中国人工智能学会通讯》——8.27 结束语
查看>>
服务企业互联网化用友进入3.0时代
查看>>
《中国人工智能学会通讯》——4.4 视频结构化描述技术在平安城市中 的应用...
查看>>
Fortinet FortiGuard安全实验室解密APT攻击的那些事儿
查看>>
用友云重装出发:你想得到的企业服务都在这
查看>>
经典网络的ECS实例支持升级到企业级实例
查看>>
《网络空间欺骗:构筑欺骗防御的科学基石》一2.3 欺骗型安全技术
查看>>
当“双态IT”已成共识 如何打造以数据驱动的运维平台?
查看>>
定位与大数据邂逅,Wi-Fi大不相同
查看>>
物联网技术正颠覆零售行业
查看>>