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:  

 

你可能感兴趣的:(nginx,CentOS)