如何通过不同的端口(80除外)启动nginx

Zha*_*eng 3 ubuntu nginx

嗨,我是 nginx 的新手,我尝试在我的服务器(运行 Ubuntu 4)上设置它,该服务器已经运行了 apache。

所以在我完成apt-get install之后,我尝试启动 nginx。然后我收到这样的消息:

Starting nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
configuration file /etc/nginx/nginx.conf test is successful
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
Run Code Online (Sandbox Code Playgroud)

这是有道理的,因为 Apache 正在使用端口 80。

然后我尝试修改nginx.conf,我参考了一些文章,所以我改成了这样:

   server {

        listen       8080;

        location / {
         proxy_pass  http://94.143.9.34:9500;
         proxy_set_header   Host             $host:8080;
         proxy_set_header   X-Real-IP        $remote_addr;
         proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
         proxy_set_header Via    "nginx";
        }
Run Code Online (Sandbox Code Playgroud)

保存并尝试再次启动 nginx 后,我仍然遇到与以前相同的错误。我真的找不到关于此的相关帖子,有没有好心人可以提供一些线索?

我应该在这里发布 conf 中的所有内容:

user www-data;
worker_processes  1;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
    # multi_accept on;
}

http {
    include       /etc/nginx/mime.types;

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

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
    tcp_nodelay        on;

    gzip  on;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;

   server {

        listen       81;

        location / {
         proxy_pass  http://94.143.9.34:9500;
         proxy_set_header   Host             $host:81;
         proxy_set_header   X-Real-IP        $remote_addr;
         proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
         proxy_set_header Via    "nginx";
        }


    }
}

 mail {
      # See sample authentication script at:
      # http://wiki.nginx.org/NginxImapAuthenticateWithApachePhpScript

      auth_http localhost/auth.php;
      pop3_capabilities "TOP" "USER";
      imap_capabilities "IMAP4rev1" "UIDPLUS";

     server {
         listen     localhost:110;
         protocol   pop3;
         proxy      on;
     }

     server {
         listen     localhost:143;
         protocol   imap;
         proxy      on;
     }
 }
Run Code Online (Sandbox Code Playgroud)

基本上,除了添加服务器部分之外,我什么都没做。

Saš*_*ašo 5

您似乎在sites_enabled文件夹中保留了默认服务器配置。

有问题的文件有一堆注释掉的行,但并非全部都是 - 默认配置纠缠在其中。我建议您删除整个文件(如果所有配置都在同一个文件中,则删除第一部分)。

但是,如果你在那里找不到它,我建议你搜索80。它肯定在nginx配置文件中的某个地方。