macos - 为什么 nginx 运行在 8080 端口而不是 81 端口?
问题描述
根据brew info nginx
终端输出告诉我nginx
默认情况下在端口 8080 上运行:
/usr/local/etc/nginx/nginx.conf 中的默认端口已设置为 8080,以便 nginx 无需 sudo 即可运行。
这是完整的输出:
$ 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)
我的 Mac OS 是 Catalina 10.15
但是,当我查看nginx.conf
in时,/usr/local/etc/nginx/nginx.conf
我没有看到 nginx 端口在 8080 上打开。我看到它在端口 81 上打开:
server {
listen 81;
server_name localhost;
....
....
当我去访问时,http://localhost:8080/
我会收到 nginx 欢迎消息。但是,当我去访问时,http://localhost:81/
我收到“无法访问站点”ERR_CONNECTION_REFUSED
错误。
8080
如果文件中没有这样的规范,nginx 如何在端口上运行nginx.conf
?以及为什么nginx
没有81
在 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/*;
}
解决方案
您是否尝试过重新启动/重新加载 Nginx?为了使配置更改生效,您需要重新加载它。
您可以在 Mac OSX 上使用此命令重新加载 Nginx:sudo nginx -s reload
推荐阅读
- gradle - Flutter 安装 Gradle 问题
- reactjs - 如何访问 Virtualbox 中的反应应用程序
- python - 写文件有问题
- mysql - 从数据库中查询 2 个不同服务器的数据
- validation - 当必需的输入字段为空时,不会触发 PrimeFaces ajax 更新
- javascript - 使用 fetch 检索数据时,Vue JS 组件没有反应
- java - Jhipster 实体子生成器:如何创建 liquibase DELTA 更改日志?
- javascript - 坚持如何从打字稿中的数组计算模式
- aem - 如何从吊索资源中获取选择器
- sql - 构建将数据插入到接收到的表中的存储过程