修改nginx端口

修改nginx端口

我想在同一台机器上运行 apache 和 nginx。我配置了 apache,它在端口 80 上运行良好。现在我想在端口 7007 上配置 nginx。我在 nginx.conf 中做了一些更改。以下是 nginx.conf 文件 -

user nginx root;
worker_processes  3;
worker_rlimit_nofile 200000;


error_log   /var/log/nginx/error.log;
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;

pid        /var/run/nginx.pid;


events {
    worker_connections  65535;
    use epoll;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
        index index.php index.htm index.html;
    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  /var/log/nginx/access.log  main;
    access_log off;

    sendfile        on;
    tcp_nopush      on;
   tcp_nodelay     on;
    server_tokens   off;
    gzip            on;
    gzip_static     on;
    gzip_comp_level 5;
    gzip_min_length 1024;
    keepalive_timeout  80 15;
  #  limit_conn_zone   $binary_remote_addr  zone=addr:10m;


    include /etc/nginx/conf.d/*.conf;

    server {
#        limit_conn addr 20000;

        listen       7007;
        server_name  _;




            root   /usr/share/nginx/html;
        location / {


        }

        error_page  404              /404.html;

        location = /404.html {
  }
        location /favicon.ico {
            empty_gif;
        }


        error_page   500 502 503 504  /50x.html;
        location = /50x.html {

        }

 location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;
            include        fastcgi_params;
            fastcgi_connect_timeout 8m;
            fastcgi_send_timeout  8m;
        }

#        location ~ \.php$ {
#            root           /usr/share/nginx/html;
            #fastcgi_pass   localhost:9000;
#            fastcgi_pass   unix:/tmp/php.sock;
#            fastcgi_index  index.php;
            #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            #include        fastcgi_params;
#           fastcgi_send_timeout  8m;

#           fastcgi_connect_timeout 8m;
            #uwsgi_pass_request_body off;
#           include /etc/nginx/fastcgi.conf;
 #       }

        location /status {
                stub_status on;
                access_log   off;
        #       allow ;
        #        allow 127.0.0.1;
        #        deny all;
        }

    }

}

当我启动 Nginx 时,它显示作业失败。这是日志。

Mar  7 15:55:12 localhost nginx[10973]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Mar  7 15:55:12 localhost nginx[10973]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Mar  7 15:55:12 localhost nginx[10975]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Mar  7 15:55:12 localhost nginx[10975]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Mar  7 15:55:13 localhost nginx[10975]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Mar  7 15:55:13 localhost nginx[10975]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Mar  7 15:55:14 localhost nginx[10975]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Mar  7 15:55:14 localhost nginx[10975]: nginx: [emerg] still could not bind()
Mar  7 15:55:14 localhost systemd[1]: nginx.service: control process exited, code=exited status=1
Mar  7 15:55:14 localhost systemd[1]: Unit nginx.service entered failed state.

为什么它仍使用 80 端口?

答案1

1)确保 /etc/nginx/sites-enabled 中没有使用端口 80 的配置文件

2) 尝试停止然后启动 Nginx,而不是重新启动它。有时,更改端口可能会导致重新启动出现问题。

相关内容