nginx 监听端口问题

因需求在搭建web的时候需要将ngin监听端口改为其他(非80端口),

1. 修改配置文件

[root@localhost html]# vim /etc/nginx/conf.d/default.conf 

修改

    listen  8085;#监听8085
    server_name  localhost;

ok,启动nginx服务

[root@localhost /]# systemctl start nginx.service
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

发生错误无法发启动

运行systemctl status nginx.service

[root@localhost /]# systemctl status nginx.service
● nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Mon 2018-10-01 02:34:00 CST; 4s ago
     Docs: http://nginx.org/en/docs/
  Process: 51507 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=1/FAILURE)
  Process: 94488 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=1/FAILURE)
 Main PID: 40098 (code=exited, status=0/SUCCESS)

Oct 01 02:33:59 localhost.localdomain systemd[1]: Starting nginx - high performance web server...
Oct 01 02:33:59 localhost.localdomain nginx[94488]: nginx: [emerg] bind() to 0.0.0.0:8085 failed (13: Permission denied)
Oct 01 02:34:00 localhost.localdomain systemd[1]: nginx.service: control process exited, code=exited status=1
Oct 01 02:34:00 localhost.localdomain systemd[1]: Failed to start nginx - high performance web server.
Oct 01 02:34:00 localhost.localdomain systemd[1]: Unit nginx.service entered failed state.
Oct 01 02:34:00 localhost.localdomain systemd[1]: nginx.service failed.

发现nginx无打开端口权限,检查是否被占用

[root@localhost /]# semanage port -l | grep 8085
[root@localhost /]# 

无占用

开启8085端口

[root@localhost /]# semanage port -a -t http_port_t -p tcp 8085

开启nginx 服务

[root@localhost /]# systemctl start nginx.service
[root@localhost /]# 

OK,查看nginx是否运行

[root@localhost /]# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:8085            0.0.0.0:*               LISTEN      97153/nginx: master 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1421/sshd           
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1418/cupsd          
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1630/master         
tcp6       0      0 :::22                   :::*                    LISTEN      1421/sshd           
tcp6       0      0 ::1:631                 :::*                    LISTEN      1418/cupsd          
tcp6       0      0 ::1:25                  :::*                    LISTEN      1630/master         
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           1020/avahi-daemon:  
udp        0      0 0.0.0.0:68              0.0.0.0:*                           4168/dhclient       
udp        0      0 0.0.0.0:32880           0.0.0.0:*                           1020/avahi-daemon:  

 

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值