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

嗨,我是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) 

这是有道理的,因为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,我仍然得到和以前一样的错误。 我真的不能find相关的post,有没有好的人可以点亮一下?

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

 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文件夹中保留了默认的服务器configuration。

有问题的文件有一堆注释掉的行,但不是全部 – 默认的configuration是纠结在其中。 我build议你删除整个文件(或者第一部分,如果你的所有configuration都在同一个文件中)。

但是,如果你不能在那里find它,我build议你做一个search80.它必然是在Nginx的configuration文件的某处。

我正在使用VMWare并有相同的错误。

我删除了我的默认configuration为sites_enabled,但也被删除:

 listen [::]:80 

…从我的configuration文件(以前需要为MacPorts)。 我不确定哪个端口VMWare监听,但它不喜欢80!