部署 Nginx 修改默认端口无效

ghn645568344 · 2016年08月08日 · 最后由 zangtian2 回复于 2017年08月19日 · 10326 次阅读

跟据实战圣经部署项目 启动 nginx 的时候发现 80 端口被占用了,修改/etc/nginx/sites-available 下的 default

server {
        listen 8083 default_server;
        listen [::]:8083 default_server ipv6only=on;

        root /usr/share/nginx/html;
        index index.html index.htm;

把端口改为 8083,再重新启动后还是报 80 错

Starting nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()

查了好多,都说修改重启服务就行了,可是我这就是改不过来,请问各位大哥,该怎么改?

https://ihower.tw/rails4/deployment.html

别看 default 的 看 conf 下的 nginx.conf,看里面是否 80 被占用了

#1 楼 @yingce 刚才问了下同事,确定 80 被占用了,

tcp6       0      0 :::80                   :::*                    LISTEN      off (0.00/0/0)

nginx.conf 这个下面没有发现有关 80 端口的

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
        worker_connections 768;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;
        gzip_disable "msie6";

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

        ##
        # nginx-naxsi config
        ##
        # Uncomment it if you installed nginx-naxsi
                                                                                                                                                            1,1           Top

sudo ss -tulpn | gawk '{printf "%-6s %-9s %-19s %s\n", $1, $2, $5, $7}' 查下哪个进程占用了 80 端口。

  • 查看端口占用情况,除了 ss, netstat,还可以:lsof -i 80。解释 http://explainshell.com/explain?cmd=lsof+-i+80
  • 查看 Nginx 配置,除了看所有的 conf(主配置,include 等),还可以:sudo nginx -T

你好,请问这个问题你解决了吗,如何修改 80 端口为其他的。 不想将占用 80 端口的服务结束掉。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号