nginx 代理本地的html

一曲冷凌霜 提交于 2020-12-28 19:32:17

编辑nginx.conf

 

Java代码    收藏代码
  1. server {  
  2.        listen       80;  
  3.        server_name  localhost;  
  4.   
  5.        #charset koi8-r;  
  6.   
  7.        #access_log  logs/host.access.log  main;  
  8.   
  9.        location / {  
  10.            root   html;        ## 指向nginx 安装目录下的html文件夹,看具体配置  
  11.            index  noindex.htm;  
  12.            autoindex on;  
  13.        }  
  14.   
  15.        location /www/ {  
  16.            root /home/admin/;   ##会指向/home/admin/www  
  17.            autoindex on;       ##会自动显示资源目录  
  18.            index noindex.htm;        
  19.        }  

 

 

通过浏览器范围 localhost/www/index.htm,访问时出现403。

Nginx的error.log 报以下错误: *2658 open() “/xxx/xxxx(dir path)” failed (13: Permission denied)

 

确定为权限问题,在nginx.conf 中增加用户配置

 

Java代码    收藏代码
  1. user admin users;  

 

 

查看work process的所属用户

 

Html代码    收藏代码
  1. [admin@wuzhongarch ~]$ ps -ef | grep nginx  
  2. root     12195     1  0 15:06 ?        00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/conf/nginx.conf  
  3. admin    12196 12195  0 15:06 ?        00:00:00 nginx: worker process   

 

文件目录的组和权限

 

Html代码    收藏代码
  1. [admin@wuzhongarch ~]$ ll | grep www  
  2. drwxr-xr-x  4 admin users     4096 Feb  2 15:05 www/  

 

这样就可以正常浏览访问了。。

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!