微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

嗨我是Nginx上的新手,我试图在我的服务器上运行它(运行Ubuntu 4),它已经运行了apache.

所以在我apt-get安装之后,我尝试启动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)

这是有道理的,因为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";
        }

保存后再尝试再次启动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;
     }
 }

基本上,除了添加服务器部分外,我什么也没做.

您似乎已将sites_enabled文件夹中的认服务器配置保留下来.

有问题的文件有一堆注释掉的行,但不是全部 – 认配置在它们之间纠结.我建议您删除整个文件(如果所有配置都在同一个文件中,则删除第一部分).

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

原文地址:https://www.jb51.cc/ubuntu/347692.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐