简体   繁体   English

403禁止的Nginx

[英]403 Forbidden Nginx

I am using nginx as web server for running html contents. 我正在使用nginx作为运行html内容的Web服务器。 When I copy my index.html into /usr/share/nginx destination it is working fine loading web page. 当我将index.html复制到/ usr / share / nginx目标时,它可以正常加载网页。 But my project located in /var/www/example.com directory. 但是我的项目位于/var/www/example.com目录中。 When i give that path into nginx.conf it is getting error 403 Forbidden. 当我将该路径输入nginx.conf时,它收到错误403 Forbidden。

Below I attached nginx.conf. 下面我附加了nginx.conf。

nginx的

i am new to this and any suggestions would be really helpful. 我对此并不陌生,任何建议都将非常有帮助。

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
worker_connections 1024;
}

http {
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  /var/log/nginx/access.log  main;

sendfile            on;
tcp_nopush          on;
tcp_nodelay         on;
keepalive_timeout   65;
types_hash_max_size 2048;

include             /etc/nginx/mime.types;
default_type        application/octet-stream;

# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;

server {
    listen       80 default_server;`enter code here`
    listen       [::]:80 default_server;
    server_name  _;
    root         /var/www/example.com;
    index         index.html;



    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location / {
    }

    error_page 404 /404.html;
        location = /40x.html {
    }

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
# Settings for a TLS enabled server.
#
#    server {
#        listen       443 ssl http2 default_server;
#        listen       [::]:443 ssl http2 default_server;
#        server_name  _;
#        root         /usr/share/nginx/html;
#
#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
#        ssl_session_cache shared:SSL:1m;
#        ssl_session_timeout  10m;
#        ssl_ciphers HIGH:!aNULL:!MD5;
#        ssl_prefer_server_ciphers on;
#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#
#        location / {
#        }
#
#        error_page 404 /404.html;
#            location = /40x.html {
#        }
#
#        error_page 500 502 503 504 /50x.html;
#            location = /50x.html {
#        }
#    }

Incorrect file permissions are another cause of the "403 Forbidden" error. 错误的文件权限是导致“ 403 Forbidden”错误的另一原因。 The standard setting of 755 for directories and 644 for files is recommended for use with NGINX. 建议与NGINX一起使用目录的755和文件的644的标准设置。 The NGINX user also needs to be the owner of the files. NGINX用户还必须是文件的所有者。

Identify the NGINX User To begin, you will need to determine what user NGINX is running as. 识别NGINX用户首先,您需要确定NGINX以哪个用户身份运行。 To do this, use the command: 为此,请使用以下命令:

ps -ef | ps -ef | grep nginx grep nginx

Check the first column, for any of the NGINX worker processes: 检查第一列是否有任何NGINX工作进程:

In this example, the NGINX worker process is running as the user nginx. 在此示例中,NGINX工作进程以用户nginx的身份运行。

Set File Ownership Go to the directory above the website's document root. 设置文件所有权转到网站文档根目录上方的目录。 For example, if your website's document root is /usr/share/nginx/example.com go to /usr/share/nginx with the command: 例如,如果您网站的文档根目录为/usr/share/nginx/example.com,请使用以下命令转到/ usr / share / nginx:

cd /usr/share/nginx 光盘/ usr / share / nginx

Change the ownership of all the files from this point down to the nginx user with the command: 使用以下命令将所有文件的所有权从此点更改为nginx用户:

sudo chown -R nginx:nginx * 须藤chown -R nginx:nginx *

Set the permissions of each directory at this location to 755 with the command: 使用以下命令将此位置的每个目录的权限设置为755:

sudo chmod 755 [directory name]mixed For example, to set the permissions of the example.com directory, the command is: sudo chmod 755 [目录名]混合例如,要设置example.com目录的权限,命令为:

sudo chmod 755 example.commixed Then go to the web document root directory: sudo chmod 755 example.commixed然后转到Web文档的根目录:

cd example.commixed Change the permissions of all the files in this directory with the command: cd example.commixed使用以下命令更改此目录中所有文件的权限:

sudo chmod 644 * 须藤chmod 644 *

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM