xyq167477
2017-01-06 08:36
采纳率: 40%
浏览 2.1k

求帮助,Linux安装Nginx后改了根目录报403

没改之前还有欢迎。。。。。啥的改了之后图片说明
我修改的是下面三个地方,原来的都是html;
图片说明
图片说明
除了报403,里面的图片可以看图片说明
关于权限,我都设置了777
图片说明
图片说明
图片说明

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

9条回答 默认 最新

  • Mr-Yao 2017-01-06 11:47
    已采纳

    我的意思是先把:
    location / {
    root /home/ftpuser/www;
    index index.html index.htm;
    }
    还原成:
    location / {
    root html;
    index index.html index.htm;
    }
    再新增新增一个location:
    location ~ .*.(gif|jpg|jpeg|png)$ {
    root /home/ftpuser/www;
    index index.html index.htm;
    }

    点赞 打赏 评论
  • xyq167477 2017-01-06 09:29

    图片说明

    点赞 打赏 评论
  • oyljerry 2017-01-06 09:33

    注意路径的拼接,你可以看看nginx的error.log中会有最后拼接访问的路径,这样就知道你修改路径后,为什么拼接的路径不正确了

    点赞 打赏 评论
  • xyq167477 2017-01-06 10:10
     #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;
    
    #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   /home/ftpuser/www;
                index  index.html index.htm;
            }
    
            #error_page  404              /404.html;
    
    
    #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   /home/ftpuser/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   /home/ftpuser/www;
            }
    
            # 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           /home/ftpuser/www;
            #    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;
            #}
        }
    
    
        # 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;
    
        #    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;
        #    }
        #    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;
        #    }
        #}
    
    }
    ``
    
    
    点赞 打赏 评论
  • Mr-Yao 2017-01-06 10:19

    我没记错的话,root后面的目录是从Ng的安装根目录开始算起。照你这个配置,应该会找到ng的安装根目录/home/ftpuser/www。不知道说的对不对

    点赞 打赏 评论
  • Mr-Yao 2017-01-06 10:41

    抱歉刚才没看懂你的问题。你是说你改了配置之后,图片可以正确访问,但是其他请求报错是吧?我看你把所有请求全部指向了/home/ftpuser/www
    而这个文件夹里面只放了图片,所以你能正确访问图片,其他请求会报错。
    这里应该改一下:
    location / {
    root /home/ftpuser/www;
    index index.html index.htm;
    }
    先还原。任何新增一个location:
    location ~ .*.(gif|jpg|jpeg|png)$ {
    root /home/ftpuser/www;
    index index.html index.htm;
    }

    点赞 打赏 评论
  • xyq167477 2017-01-06 11:27
             #access_log  logs/host.access.log  main;
    
            location / {
                root   /home/ftpuser/www;
                index  index.html index.htm;
            }
        location ~ .*.(gif|jpg|jpeg|png)$ {
            root   /home/ftpuser/www;
            index  index.html index.htm;
        }
            #error_page  404              /404.html;
    

    改成这样么?

    点赞 打赏 评论
  • xyq167477 2017-01-06 11:37

    我的想法就是输入http://192.168.44.128/ 后显示那个Nginx的欢迎页面

    点赞 打赏 评论
  • xyq167477 2017-01-06 11:39

    图片说明

    点赞 打赏 评论

相关推荐 更多相似问题