如何在Nginx中更改服务器主机名

时间:2019-03-11 23:45:53

标签: nginx centos centos7 nginx-config

我正在尝试使用其他主机名在端口80中启动Nginx服务器。

当前,端口80受Apache约束,实际上,服务器中还有其他站点,即CentOS 7。

我需要使用与Apache无关的其他虚拟主机使用相同的端口来启动ngix。

我尝试通过修改以下内容来修改fila:/etc/nginx/conf.d/default.conf:

listen       hostname:80;
server_name  hostname;

但是没有用。甚至,我将端口更改为8080进行测试,但是当我运行“ systemctl status nginx.service”时,它始终会响应:

 nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Mon 2019-03-11 20:32:52 -03; 7min ago
     Docs: http://nginx.org/en/docs/
  Process: 22790 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=1/FAILURE)

Mar 11 20:32:49 vps.desytec.com nginx[22790]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Mar 11 20:32:50 vps.desytec.com nginx[22790]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Mar 11 20:32:50 vps.desytec.com nginx[22790]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Mar 11 20:32:51 vps.desytec.com nginx[22790]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Mar 11 20:32:51 vps.desytec.com nginx[22790]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Mar 11 20:32:52 vps.desytec.com nginx[22790]: nginx: [emerg] still could not bind()
Mar 11 20:32:52 vps.desytec.com systemd[1]: nginx.service: control process exited, code=exited status=1
Mar 11 20:32:52 vps.desytec.com systemd[1]: Failed to start nginx - high performance web server.
Mar 11 20:32:52 vps.desytec.com systemd[1]: Unit nginx.service entered failed state.
Mar 11 20:32:52 vps.desytec.com systemd[1]: nginx.service failed.

最后,这是/etc/nginx/nginx.conf文件:

user  nginx;

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

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    server_names_hash_bucket_size 64;

    client_max_body_size 64m;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log main buffer=16k;

    sendfile        on;
    tcp_nopush      on;
    tcp_nodelay     on;

    keepalive_timeout  65;
    keepalive_requests 100;

    #gzip  on;



    include /etc/nginx/conf.d/*;
}

有什么帮助吗?

谢谢 海梅

0 个答案:

没有答案