简体   繁体   English

为什么 nginx 运行在端口 8080 而不是 81?

[英]Why is nginx running on port 8080 but not 81?

Based on brew info nginx the terminal output is telling me that nginx is running on port 8080 by default:根据brew info nginx终端 output 告诉我nginx默认在端口 8080 上运行:

The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that nginx can run without sudo.默认端口已在 /usr/local/etc/nginx/nginx.conf 中设置为 8080,以便 nginx 可以在没有 sudo 的情况下运行。

This is the full output:这是完整的 output:

$ brew info nginx
nginx: stable 1.19.0 (bottled), HEAD
HTTP(S) server and reverse proxy, and IMAP/POP3 proxy server
https://nginx.org/
/usr/local/Cellar/nginx/1.19.0 (25 files, 2.1MB) *
  Poured from bottle on 2020-06-16 at 17:55:46
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/nginx.rb
==> Dependencies
Required: openssl@1.1 ✔, pcre ✔
==> Options
--HEAD
    Install HEAD version
==> Caveats
Docroot is: /usr/local/var/www

The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.

nginx will load all files in /usr/local/etc/nginx/servers/.

To have launchd start nginx now and restart at login:
  brew services start nginx
Or, if you don't want/need a background service you can just run:
  nginx
==> Analytics
install: 33,973 (30 days), 101,534 (90 days), 407,985 (365 days)
install-on-request: 33,387 (30 days), 99,128 (90 days), 394,576 (365 days)
build-error: 0 (30 days)

My Mac OS is Catalina 10.15我的 Mac OS 是 Catalina 10.15

However, when I go to look at the nginx.conf in /usr/local/etc/nginx/nginx.conf I do not see that the nginx port is open on 8080. I see it open on port 81:但是,当我 go 查看/usr/local/etc/nginx/nginx.conf中的nginx.conf时,我看不到 nginx 在端口上打开了端口。

server {
        listen       81;
        server_name  localhost;
    ....
    ....

When I go to visit http://localhost:8080/ I get the nginx welcome message.当我 go 访问http://localhost:8080/我收到 nginx 欢迎消息。 However when I go to visit http://localhost:81/ I get a "site can't be reached" ERR_CONNECTION_REFUSED error.但是,当我 go 访问http://localhost:81/时,我收到“无法访问站点” ERR_CONNECTION_REFUSED错误。

How is nginx running on port 8080 without such a specification in the nginx.conf file?如果nginx.conf文件中没有这样的规范,nginx 如何在端口8080上运行? And why is nginx not running on port 81 which the conf appears to suggest it should.为什么nginx不在端口81上运行,conf 似乎建议它应该运行。

Here's the full nginx.conf :这是完整的nginx.conf

# cat /usr/local/etc/nginx/nginx.conf

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       81;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }


        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

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


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

    include servers/*;
}

Have you tried to restart/reload Nginx yet?您是否尝试过重新启动/重新加载 Nginx? In order for the configuration change to take effect, you need to reload it.为了使配置更改生效,您需要重新加载它。

You can use this command on Mac OSX to reload Nginx: sudo nginx -s reload您可以在 Mac OSX 上使用此命令重新加载 Nginx: sudo nginx -s reload

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM