gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 16:39:48 28 4
gpt4 key购买 nike

嗨,我是 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://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";
}

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

基本上,除了添加服务器部分外,我没有做任何更改。

最佳答案

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

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

server {
listen 81;
}

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

sudo service nginx start

您现在可以在端口 81 上访问您的应用程序(对于本地主机,http://localhost:81)。

关于ubuntu - 如何通过不同端口(80 以外)启动 nginx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10829402/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com