nginx 1.9 无法启动 80 以外的其他端口

nginx 1.9 无法启动 80 以外的其他端口

我安装了 phpmyadmin,删除了 apache2,然后在 /etc/nginx/sites-available/phpmyadmin 中进行了如下配置

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
        listen 8081;
        listen [::]:8081;

        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        root /usr/share/phpmyadmin;

        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm index.nginx-debian.html;

        #server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;

        #       # With php7.0-cgi alone:
        #       fastcgi_pass 127.0.0.1:9000;
        #       # With php7.0-fpm:
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
                deny all;
        }
}

我只能看到 80 端口打开

$ sudo netstat -tlnp | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      25160/nginx -g daem
tcp6       0      0 :::80                   :::*                    LISTEN      25160/nginx -g daem

nginx 状态似乎显示错误

$ sudo systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2016-07-10 14:43:33 MYT; 44min ago
  Process: 25150 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS)
  Process: 25157 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
  Process: 25153 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
 Main PID: 25160 (nginx)
    Tasks: 2
   Memory: 1.8M
      CPU: 54ms
   CGroup: /system.slice/nginx.service
           ├─25160 nginx: master process /usr/sbin/nginx -g daemon on; master_process on
           └─25161 nginx: worker process

Jul 10 14:43:33 ubuntu systemd[1]: Stopped A high performance web server and a reverse proxy server.
Jul 10 14:43:33 ubuntu systemd[1]: Starting A high performance web server and a reverse proxy server...
Jul 10 14:43:33 ubuntu systemd[1]: nginx.service: Failed to read PID from file /run/nginx.pid: Invalid argument
Jul 10 14:43:33 ubuntu systemd[1]: Started A high performance web server and a reverse proxy server.

php7.0-fpm 似乎没问题

$ sudo systemctl status php7.0-fpm
● php7.0-fpm.service - The PHP 7.0 FastCGI Process Manager
   Loaded: loaded (/lib/systemd/system/php7.0-fpm.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2016-07-10 14:46:02 MYT; 46min ago
  Process: 25178 ExecStartPre=/usr/lib/php/php7.0-fpm-checkconf (code=exited, status=0/SUCCESS)
 Main PID: 25187 (php-fpm7.0)
   Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
    Tasks: 3
   Memory: 18.2M
      CPU: 272ms
   CGroup: /system.slice/php7.0-fpm.service
           ├─25187 php-fpm: master process (/etc/php/7.0/fpm/php-fpm.conf)
           ├─25190 php-fpm: pool www
           └─25191 php-fpm: pool www

Jul 10 14:46:02 ubuntu systemd[1]: Stopping The PHP 7.0 FastCGI Process Manager...
Jul 10 14:46:02 ubuntu systemd[1]: Stopped The PHP 7.0 FastCGI Process Manager.
Jul 10 14:46:02 ubuntu systemd[1]: Starting The PHP 7.0 FastCGI Process Manager...
Jul 10 14:46:02 ubuntu systemd[1]: Started The PHP 7.0 FastCGI Process Manager.

我的配置有错误吗?

答案1

将 /etc/nginx/sites-available/phpmyadmin 符号链接到 /etc/nginx/sites-enabled/phpmyadmin 并重新启动 nginx

# ln -s /etc/nginx/sites-available/phpmyadmin /etc/nginx/sites-enabled/

这是因为应该这样做以便将新的服务器块文件添加到 nginx 工作中。

相关内容