Linux安装Nginx与403 Forbidden问题

阿里 阅读:676 2021-04-01 11:07:37 评论:0

1、root用户安装nginx
1.安装

	[root]# yum install -y nginx 
	#如果:没有可用软件包 nginx。 
	# yum install epel-release 
	#设置nginx开机启动 
	[root]# chkconfig nginx on 
	#启动nginx 
	[root]# service nginx start 
注如果:Starting nginx: nginx: [emerg] socket() [::]:80 failed (97: Address family not supported by protocol) 
将: /etc/nginx/conf.d/default.conf 
		listen       80 default_server; 
   		listen       [::]:80 default_server; 
  改为: 
  		listen       80; 
  		#listen       [::]:80 default_server; 

2.配置

	首页:/usr/share/nginx/html 
	配置:/etc/nginx/conf.d/default.conf   或者 /etc/nginx 

3.niginx反向代理 80端口转9030端口

server { 
        listen       80 default_server; 
        listen       [::]:80 default_server; 
        server_name  _; 
        root         /usr/share/nginx/html; 
 
        # Load configuration files for the default server block. 
        include /etc/nginx/default.d/*.conf; 
 
		location / { 
        } 
		location /sjjz-service { 
			proxy_pass http://127.0.0.1:9030/sjjz-service; 
			proxy_set_header Host $host:80; 
			proxy_set_header X-Real-IP $remote_addr; 
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
			proxy_set_header Via "nginx"; 
        } 
        error_page 404 /404.html; 
            location = /40x.html { 
        } 
 
        error_page 500 502 503 504 /50x.html; 
            location = /50x.html { 
        } 
    } 

4.访问项目出现Nginx 403 Forbidden问题

http://192.168.253.100/sjjz-service/swagger-12IZ/index.html#3de2cc4d5f3140b6952822c878d33eac 

报错查看日志/var/log/nginx发现

2020/07/23 13:40:32 [crit] 86712#0: *1 connect() to 127.0.0.1:9030 failed (13: Permission denied) while connecting to upstream, client: 10.0.1.122, server: _, request: "GET /sjjz-service/swagger-12IZ/index.html HTTP/1.1", upstream: "http://127.0.0.1:9030/sjjz-service/swagger-12IZ/index.html", host: "192.168.253.100" 

4.1.selinux问题
a.查看是否开启 sestatus -v,若显示SELinux status: enabled代表开启了selinux
b.临时关闭

setenforce 0设置为permissive(setenforce 1 )代表enforcing(强制) 

c.永久关闭

vi /etc/selinux/config 
将SELINUX=enforcing改为SELINUX=disabled 
设置完成后重启才生效 

4.2.修改user
nginx.conf 修改内容 user root;
4.3修改要访问目录权限

#other用户 rx权限 
chmod -R 755 / app/front-end 
标签:nginx
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

关注我们

一个IT知识分享的公众号