【问题标题】:Antergos Linux - LEMP stack - Nginx 403Antergos Linux - LEMP 堆栈 - Nginx 403
【发布时间】:2016-10-31 07:08:39
【问题描述】:

刚刚来到 Arch 方面。我在让我的本地 LEMP 堆栈在 Antergos 上工作时遇到了很多麻烦。目前服务器阻止本地页面返回 403 错误。

/etc/nginx/nginx.conf:

#user html;
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;
    include       sites-enabled/*;
    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   /usr/share/nginx/html;
            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   /usr/share/nginx/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;
        #}
    }


    # 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;
    #    }
    #}

}

/etc/nginx/sites-available/projects.local

server {
    listen 80;
    #listen [::]:80;

    server_name project.local www.project.local;

    root /home/l/install/project/www;

    access_log  /home/l/install/project/www/log/access.log;
    error_log   /home/l/install/project/www/log/error.log;

        location / {
            index index.html index.htm index.php;
        }

        location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }

}

以及错误日志中的最后一条:

“GET /test/index.html HTTP/1.1”,主机:“project.local” 2016/06/28 12:18:45 [错误] 28652#28652: *1 open() “/home/l/install/project/www/test”失败(13:权限被拒绝), 客户端:127.0.0.1,服务器:project.local,请求:“GET /test HTTP/1.1”,主机:“project.local”

www 文件夹的 ls -la 显示:

[l@l 项目]$ ls -la 共 12 个 drwxr-xr-x 3 l 用户 4096 Jun 28 10:14 。 drwxr-xr-x 4 l 用户 4096 Jun 28 10:13 .. drwxrwxrwx 4 l 用户 4096

www文件夹里面有一个test文件夹,还有'l users'和test文件夹里面的index.php也分别属于l和users。

编辑:被视为已结束的问题。移至 Ubuntu 16.04 Gnome。

【问题讨论】:

    标签: php linux nginx


    【解决方案1】:

    尝试将您的www 目录移到/home 之外。例如,您可以将其移动到 /srv/www 并将目录的所有者更改为 html 用户和组:

    sudo mv /home/l/www /srv
    sudo chown -R html:html /srv/www
    

    请务必相应地更新您的nginx.conf。希望对您有所帮助!

    【讨论】:

    • 我之前尝试过服务器块(虚拟主机)和 chown 命令。暂时我切换回 Ubuntu Gnome。还是谢谢你!!
    【解决方案2】:

    我看到“问题被认为已结束”这一行,但为了其他可能会遇到此问题的人,我会给出答案。

    如果您由于各种原因不喜欢更改所有者/组,则可以通过更改权限来摆脱困境。您需要文件的读取权限(假设您没有更改它们)。要访问文件夹,您需要读取和执行。

    因此:

    chmod -R o+rx /home/1/www
    

    请注意,这对于实时站点来说可能不是一个好主意,但应该将其删减以用于测试目的。

    【讨论】:

    • 谢谢。页面会频繁更改,如一分钟几次。这是一个开发环境。
    猜你喜欢
    • 2014-11-20
    • 2017-11-17
    • 2016-02-29
    • 1970-01-01
    • 2019-08-16
    • 2021-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多