资讯专栏INFORMATION COLUMN

nginx 配置 默认网站根目录(权限问题导致403 Forbidden错误的解决方法)

AWang / 1597人阅读

摘要:在安装服务器后,我想把网站的根目录设置为,于是对的文件进行配置先打开设置的地方保存后,重启服务,然后出现了错误网上查询后说是权限问题,更改的第一行将改为保存,再次重启服务,访问成功如果不想使用用户运行,就不能把目录放在目录下了,可以选

在安装 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,同样可以访问成功。

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/39355.html

相关文章

  • 跨域解决方案(史上最易懂)

    摘要:跨域总结跨域思路跨域解决方案一般分为两种前端解决,后端解决前端解决方案通过前端解决的思想就是,通过设置中间件把跨域的请求转发一下,其实就是反向代理,比如想要访问豆瓣的接口很会有跨域问题,但是如果请求的是就不存在跨域反向代理就是截取之后的请求 跨域总结 1.跨域思路 跨域解决方案一般分为两种:前端解决,后端解决 1.1 前端解决方案 通过前端解决的思想就是,通过设置中间件把跨域的请求转发...

    wh469012917 评论0 收藏0
  • nginx静态资源文件无法访问,403 forbidden错误

    摘要:今天在搭建环境时出现一个奇怪问题,配置的静态资源目录下面文件无法访问,浏览器访问出现,环境是图片是通过后台程序上传到服务器的,检查之后发现是程序创建的文件夹没有访问权限导致的图片无法访问。解决方法是在配置文件头部加打开配置文件修改 今天在搭建nginx环境时出现一个奇怪问题,配置的静态资源目录下面文件无法访问,浏览器访问出现403 forbidden,环境是centos6.8 + ng...

    Benedict Evans 评论0 收藏0
  • linux部署Nginx以及简易图片服务器搭建

    摘要:与主要区别在于如何解释后面的,这会使两者分别以不同的方式将请求映射到服务器文件上。实例如果一个请求的是时,服务器将会返回服务器上的的文件。 Linux 部署nginx 环境: 百度云实例 CentOS / 7.5 x86_64 (64bit) 安装依赖 yum install gcc yum install pcre-devel yum install zlib zlib-dev...

    soasme 评论0 收藏0
  • 跨域解决方案(易懂,持续更新中……)

    摘要:跨域总结跨域思路跨域解决方案一般分为两种前端解决,后端解决前端解决方案通过前端解决的思想就是,通过设置中间件把跨域的请求转发一下,其实就是反向代理,比如想要访问豆瓣的接口很,但是如果请求的是就不存在跨域反向代理就是截取之后重写请求将请求转发 跨域总结 1.跨域思路 跨域解决方案一般分为两种:前端解决,后端解决 1.1 前端解决方案 通过前端解决的思想就是,通过设置中间件把跨域的请求转发...

    wupengyu 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<