请求nginx静态资源报403
生活随笔
收集整理的這篇文章主要介紹了
请求nginx静态资源报403
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
【README】
請求nginx靜態資源報403;
【1】原因
靜態資源防止在某個家目錄下,如 /root 目錄下
【2】 解決方法1
nginx.conf 文件沒有指定用戶?
# user nobody
修改為
user? root;? # 設置為root用戶 ;
【例子】
user root; #使用root用戶訪問 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 {# load balance config upstream myserver {# ip_hash; # fair; server 192.168.163.201:8080 weight=10;server 192.168.163.204:8080 weight=50;} 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 192.168.163.204;error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}location / {proxy_pass http://myserver; root html;index index.html index.htm;}location /test01 {proxy_pass http://myserver/test01/;}location /test02 {proxy_pass http://myserver/test02/;}location /www/{root /root/software/nginx/data; #root家目錄下的靜態資源index index.html index.htm;}location /image/ {root /root/software/nginx/data;autoindex on;}}}訪問效果
【3】解決方法2
把nginx靜態資源放置在其他地方, 如? /home/nginx下,并將其權限設置為777 ;
【例子】
靜態資源目錄結構如下:
[root@localhost data]# pwd /home/nginx/data [root@localhost data]# tree . ├── image2 │?? └── home.png └── www2└── home.html2 directories, 2 files [root@localhost data]# ll total 0 drwxr-xr-x. 2 root root 22 Aug 7 20:07 image2 drwxr-xr-x. 2 root root 23 Aug 7 20:07 www2 [root@localhost data]# cd .. [root@localhost nginx]# ll total 0 drwxrwxrwx. 4 root root 32 Aug 7 20:22 data #777nginx配置
#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 {# load balance config upstream myserver {# ip_hash; # fair; server 192.168.163.201:8080 weight=10;server 192.168.163.204:8080 weight=50;} 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 192.168.163.204;error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}location / {proxy_pass http://myserver; root html;index index.html index.htm;}location /test01 {proxy_pass http://myserver/test01/;}location /test02 {proxy_pass http://myserver/test02/;}location /www/{root /root/software/nginx/data;index index.html index.htm;}location /image/ {root /root/software/nginx/data;autoindex on;}location /www2/{root /home/nginx/data/; # static resource located in home dirindex index.html index.htm; }location /image2/ { # static resource located in home dir root /home/nginx/data/;autoindex on;}}}訪問效果
總結
以上是生活随笔為你收集整理的请求nginx静态资源报403的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 电脑看视频最好的浏览器(专门看视频的浏览
- 下一篇: vmware安装centos8步骤