大网数据广告活动
服务器运维问答

nginx 1.12.2 not binding to ports on Centos 7.4

· 52CE 我爱测

I have installed nginx via yum on Centos 7.4. I've added some sites to /etc/nginx/conf.d that listen on port 80. Here is an example: server { listen 80; root /var/www/vhosts/somesite; index index.php index.html index.htm; server_…

问题原文

原帖链接 · Robert Egginton · CC BY-SA 3.0

I have installed nginx via yum on Centos 7.4. I've added some sites to /etc/nginx/conf.d that listen on port 80. Here is an example:

server {
    listen   80;

    root /var/www/vhosts/somesite;
    index index.php index.html index.htm;

    server_name api.somesite.info;

    location / {
            try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/impro.somesite.sock;
            fastcgi_index index.php;
            include fastcgi_params;
    }
}

nginx -t returns:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

The service is started as follows:

systemctl start nginx

This returns no errors. And there is no firewall installed at present.

The problem is that even if I point /etc/hosts at api.somesite.info I am getting a refused connection.

To see the ports bound, I ran netstat -ltnep, giving:

Proto Recv-Q Send-Q Local Address           Foreign Address         State       
User       Inode      PID/Program name
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      0          14585      1/systemd
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      0          18224      1105/sshd
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      0          16689      979/master
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      0          68092      4930/php-fpm: maste
tcp6       0      0 :::3306                 :::*                    LISTEN      27         51441      26589/mysqld
tcp6       0      0 :::111                  :::*                    LISTEN      0          14584      1/systemd
tcp6       0      0 :::22                   :::*                    LISTEN      0          18226      1105/sshd
tcp6       0      0 ::1:25                  :::*                    LISTEN      0          16690      979/master

So while php-fpm has bound to a port (I'm actually mostly using sockets, but that's not relevant here I don't think), nginx has not. Note that there is nothing listening to port 80 - apache is not installed by default in this version of centos.

I can see that nginx is running by running systemctl status nginx:

nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2018-04-04 15:24:04 BST; 4min 8s ago
Process: 6091 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Process: 6088 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 6086 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 6094 (nginx)
 CGroup: /system.slice/nginx.service
       ├─6094 nginx: master process /usr/sbin/nginx
       └─6095 nginx: worker process

Apr 04 15:24:04 smaractus systemd[1]: Starting The nginx HTTP and reverse proxy server...
Apr 04 15:24:04 smaractus nginx[6088]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Apr 04 15:24:04 smaractus nginx[6088]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Apr 04 15:24:04 smaractus systemd[1]: Failed to read PID from file /run/nginx.pid: Invalid argument
Apr 04 15:24:04 smaractus systemd[1]: Started The nginx HTTP and reverse proxy server.

I can see a warning here where it fails to find the pid file, but as far as I understand that's not a show stopper? Out of ideas as to where to look now. Why is nginx not binding port 80?

已采纳解答

原帖链接 · Michael Hampton · CC BY-SA 3.0

Did you happen to see this in nginx.conf?

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

This means that the name of the file in /etc/nginx/conf.d must end with .conf. Check the file's name and rename it so that it ends with .conf. With any other name it will be ignored.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-04-04)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。