如何通过不同的端口(80除外)启动nginx [英] How to start nginx via different port(other than 80)

查看:68
本文介绍了如何通过不同的端口(80除外)启动nginx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

启动nginx:配置文件/etc/nginx/nginx.conf语法没问题配置文件/etc/nginx/nginx.conf 测试成功[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,参考了一些文章,所以改成这样:

 服务器 {听8080;地点/{proxy_pass http://xx.xx.xx.xx:9500;proxy_set_header 主机 $host:8080;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header 通过nginx";}

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

提前致谢:)

==========================================================================

我应该在此处发布 conf 中的所有内容:

user www-data;worker_processes 1;error_log/var/log/nginx/error.log;pid/var/run/nginx.pid;事件{worker_connections 1024;# multi_accept on;}http {包括/etc/nginx/mime.types;access_log/var/log/nginx/access.log;发送文件;#tcp_nopush on;#keepalive_timeout 0;keepalive_timeout 65;tcp_nodelay 开启;gzip 上;gzip_disable "MSIE [1-6].(?!.*SV1)";包括/etc/nginx/conf.d/*.conf;包括/etc/nginx/sites-enabled/*;服务器 {听 81;地点/{proxy_pass http://94.143.9.34:9500;proxy_set_header 主机 $host:81;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header 通过nginx";}}}邮件 {请参阅示例身份验证脚本:http://wiki.nginx.org/NginxImapAuthenticateWithApachePhpScriptauth_http 本地主机/auth.php;pop3_capabilities "TOP" "用户";imap_capabilities "IMAP4rev1" "UIDPLUS";服务器 {听本地主机:110;协议pop3;代理开启;}服务器 {听本地主机:143;协议 imap;代理开启;}}

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

解决方案

你必须去/etc/nginx/sites-enabled/ 如果这是默认配置,那么应该有是一个文件名:default.

通过定义所需的端口来编辑该文件;在下面的代码段中,我们在端口 81 上为 Nginx 实例提供服务.

服务器{听 81;}

要启动服务器,请运行下面的命令行;

sudo service nginx start

您现在可以在端口 81 上访问您的应用程序(对于 localhost,http://localhost:81).>

Hi I am a newbie on nginx, I tried to set it up on my server(running Ubuntu 4), which already has apache running.

So after I apt-get install it, I tried to start nginx. Then I get the message like this:

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)

That makes sense as Apache is using port 80.

Then I tried to modify nginx.conf, I reference some articles, so I changed it like so:

   server {

        listen       8080;

        location / {
         proxy_pass  http://xx.xx.xx.xx: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";
        }

After saving this and try to start nginx again, I still get the same error as previously. I cannot really find a related post about this, could any good people shred some light?

Thanks in advance :)

=========================================================================

I should post all the content in conf here:

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;
     }
 }

Basically, I changed nothing except adding the server part.

解决方案

You have to go to the /etc/nginx/sites-enabled/ and if this is the default configuration, then there should be a file by name: default.

Edit that file by defining your desired port; in the snippet below, we are serving the Nginx instance on port 81.

server {
    listen 81;
}

To start the server, run the command line below;

sudo service nginx start

You may now access your application on port 81 (for localhost, http://localhost:81).

这篇关于如何通过不同的端口(80除外)启动nginx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆