无法更改nginx默认端口

2ic8powd  于 2022-12-26  发布在  Nginx
关注(0)|答案(1)|浏览(200)

我在Mac OS Sierra上安装了nginx

brew install nginx

这里有一个问题brew自动启动nginx服务,但它不应该像这样(我应该告诉我需要一个后台服务或没有!!!),但到目前为止一切顺利,localhost:8080显示默认的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       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

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

        #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/*;
}

我重新启动服务,但现在它不为8080和80服务
我试着停止服务然后自己启动

sudo nginex

我得到

nginx: [emerg] open() "/usr/local/var/run/nginx.pid" failed (2: No such file or directory)

我搜索了很多,阅读了很多关于这个问题的内容,但我没有找到类似的问题

5gfr0r5j

5gfr0r5j1#

似乎你的nginx没有运行。
检查nginx是否正在运行

$ ps -ef | grep nginx

当你看到这样的东西

0 10653     1   0  3:32PM ??         0:00.01 nginx: master process nginx
   -2 11498 10653   0  3:37PM ??         0:00.01 nginx: worker process

nginx已打开,否则未打开。
如果nginx未打开,请先运行nginx。

$ sudo nginx

如果你在nginx打开后编辑了nginx文件配置,你应该重新加载nginx。

// assumes nginx is on
$ sudo nginx -s reload

到现在为止,您应该看到更改生效。

相关问题