Nginx不关心新的虚拟主机

Nginx不关心新的虚拟主机,nginx,vhosts,Nginx,Vhosts,我正在与nginx讨论有关vhost的几个问题 当我安装我的nginx服务器时,我构建了一个虚拟主机,它目前在端口8080上工作。不是在80上,因为它似乎已经有东西在使用它了 最近我试图安装一个新的vhost,但nginx并不关心它 我在可用的/etc/nginx/站点中构建了vhost。我在/etc/nginx/sites enabled中创建了一个符号链接,它是指向我的vhost的链接 我重新启动并重新加载,但nginx总是将我重定向到默认vhost 我尝试了以下尝试: Ichmod到77

我正在与nginx讨论有关vhost的几个问题

当我安装我的nginx服务器时,我构建了一个虚拟主机,它目前在端口8080上工作。不是在80上,因为它似乎已经有东西在使用它了

最近我试图安装一个新的vhost,但nginx并不关心它

我在可用的
/etc/nginx/站点中构建了vhost。我在
/etc/nginx/sites enabled
中创建了一个符号链接,它是指向我的vhost的链接

我重新启动并重新加载,但nginx总是将我重定向到默认vhost

我尝试了以下尝试:

  • I
    chmod到775
    符号链接和vhost
  • 我将vhost直接放入
    /etc/nginx/sites enabled
  • 我将vhost的主体直接放入
    nginx.conf
  • 我删除了默认的vhost符号链接
总是重新启动并重新加载,但nginx保持将我重定向到默认vhost,即使符号链接不存在

我真的需要一些帮助,因为我开始失去理智了。我可以完全访问服务器,因此我可以提示您需要帮助我的一些反馈;)

问候,

博博恩

编辑:

在下面的代码中,vhost1工作正常,vhost2始终向我显示默认vhost的主体

nginx.conf

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

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

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

#mail {
#   # See sample authentication script at:
#   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
#   # 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/

/etc/nginx/sites-enabled$ ls -als
total 8
4 drwxr-xr-x 2 root root 4096 Feb  3 21:00 .
4 drwxr-xr-x 8 root root 4096 Feb  3 14:26 ..
0 lrwxrwxrwx 1 root root   26 Jan 25 17:47 vhost1 -> ../sites-available/vhost1
0 lrwxrwxrwx 1 root root   36 Feb  3 21:00 vhost2 -> ../sites-available/vhost2
/etc/nginx/sites-available$ ls -als
total 20
4 drwxr-xr-x 2 root root 4096 Feb  3 21:00 .
4 drwxr-xr-x 8 root root 4096 Feb  3 14:26 ..
4 -rw-r--r-- 1 root root 2416 Feb  3 13:24 default
4 -rwxr-xr-x 1 root root  823 Feb  3 13:26 vhost1
4 -rwxr-xr-x 1 root root  856 Feb  3 19:41 vhost2
/etc/nginx/sites available/

/etc/nginx/sites-enabled$ ls -als
total 8
4 drwxr-xr-x 2 root root 4096 Feb  3 21:00 .
4 drwxr-xr-x 8 root root 4096 Feb  3 14:26 ..
0 lrwxrwxrwx 1 root root   26 Jan 25 17:47 vhost1 -> ../sites-available/vhost1
0 lrwxrwxrwx 1 root root   36 Feb  3 21:00 vhost2 -> ../sites-available/vhost2
/etc/nginx/sites-available$ ls -als
total 20
4 drwxr-xr-x 2 root root 4096 Feb  3 21:00 .
4 drwxr-xr-x 8 root root 4096 Feb  3 14:26 ..
4 -rw-r--r-- 1 root root 2416 Feb  3 13:24 default
4 -rwxr-xr-x 1 root root  823 Feb  3 13:26 vhost1
4 -rwxr-xr-x 1 root root  856 Feb  3 19:41 vhost2
vhost2

server {
        listen 80;
        listen [::]:80;

        server_name dev.xxx.fr;
        root /var/www/xxx/dev/web;
        index index.html index.php;

        location / {
                try_files $uri /index.php$is_args$args;
        }

        location ~ ^/index\.php(/|$) {
                fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
                fastcgi_split_path_info ^(.+\.php)(/.*)$;
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
                fastcgi_param DOCUMENT_ROOT $realpath_root;
                internal;
        }

        location ~ \.php$ {
                return 404;
        }

        error_log /var/log/nginx/dev-xxx_error.log;
        access_log /var/log/nginx/dev-xxx_access.log;
}
目前,当我在navigator中调用vhost2时,我有:

Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.
但是我只放了一个
phpinfo()在my
index.php
中。因此,nginx似乎仍在使用默认vhost

当我对vhost进行curl调用时,我得到:

curl -I http://dev.xxx.fr

HTTP/1.1 200 OK
Server: nginx/1.14.2
Date: Mon, 03 Feb 2020 17:05:49 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Sat, 25 Jan 2020 17:25:19 GMT
Connection: keep-alive
ETag: "5e2c79ff-264"
Accept-Ranges: bytes
并且没有
-I
选项:

curlhttp://dev.xxx.fr
欢迎来到nginx!
身体{
宽度:35em;
保证金:0自动;
字体系列:Tahoma、Verdana、Arial、无衬线字体;
}
欢迎来到nginx!
如果您看到此页面,则nginx web服务器已成功安装,并且
工作需要进一步配置

有关在线文档和支持,请参阅 .
商业支持可从以下网址获得:

感谢您使用nginx

是的,即使我删除了符号链接,然后重新启动nginx,我仍然会得到默认vhost:()的html

我安装了
lsof
,然后启动
sudolsof-I:80

/etc/nginx/sites-available$ sudo lsof -i:80
COMMAND  PID     USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
nginx   9759     root   14u  IPv4 2001766      0t0  TCP *:http (LISTEN)
nginx   9759     root   15u  IPv6 2001767      0t0  TCP *:http (LISTEN)
nginx   9770 www-data   14u  IPv4 2001766      0t0  TCP *:http (LISTEN)
nginx   9770 www-data   15u  IPv6 2001767      0t0  TCP *:http (LISTEN)
nginx   9771 www-data   14u  IPv4 2001766      0t0  TCP *:http (LISTEN)
nginx   9771 www-data   15u  IPv6 2001767      0t0  TCP *:http (LISTEN)
nginx   9772 www-data   14u  IPv4 2001766      0t0  TCP *:http (LISTEN)
nginx   9772 www-data   15u  IPv6 2001767      0t0  TCP *:http (LISTEN)
nginx   9773 www-data   14u  IPv4 2001766      0t0  TCP *:http (LISTEN)
nginx   9773 www-data   15u  IPv6 2001767      0t0  TCP *:http (LISTEN)
nginx   9774 www-data   14u  IPv4 2001766      0t0  TCP *:http (LISTEN)
nginx   9774 www-data   15u  IPv6 2001767      0t0  TCP *:http (LISTEN)
nginx   9775 www-data   14u  IPv4 2001766      0t0  TCP *:http (LISTEN)
nginx   9775 www-data   15u  IPv6 2001767      0t0  TCP *:http (LISTEN)
nginx   9776 www-data   14u  IPv4 2001766      0t0  TCP *:http (LISTEN)
nginx   9776 www-data   15u  IPv6 2001767      0t0  TCP *:http (LISTEN)
nginx   9777 www-data   14u  IPv4 2001766      0t0  TCP *:http (LISTEN)
nginx   9777 www-data   15u  IPv6 2001767      0t0  TCP *:http (LISTEN)
当我尝试使用80端口时,在下面,在我尝试重新启动nginx之后,
journalctl-xe
的输出:

Feb 03 19:41:21 ns3017362 nginx[6303]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Feb 03 19:41:21 ns3017362 nginx[6303]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Feb 03 19:41:21 ns3017362 nginx[6303]: nginx: [emerg] still could not bind()
Feb 03 19:41:21 ns3017362 systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
-- Subject: Unit process exited
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- An ExecStart= process belonging to unit nginx.service has exited.
--
-- The process' exit code is 'exited' and its exit status is 1.
Feb 03 19:41:21 ns3017362 systemd[1]: nginx.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- The unit nginx.service has entered the 'failed' state with result 'exit-code'.
Feb 03 19:41:21 ns3017362 systemd[1]: Failed to start A high performance web server and a reverse proxy server.
-- Subject: A start job for unit nginx.service has failed
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- A start job for unit nginx.service has finished with a failure.
--
-- The job identifier is 91291 and the job result is failed.
Feb 03 19:41:21 ns3017362 sudo[6295]: pam_unix(sudo:session): session closed for user root
Feb 03 19:41:35 ns3017362 sudo[6308]: xxx : TTY=pts/0 ; PWD=/etc/nginx/sites-enabled ; USER=root ; COMMAND=/usr/bin/journalctl -xe
Feb 03 19:41:35 ns3017362 sudo[6308]: pam_unix(sudo:session): session opened for user root by xxx(uid=0)
Feb 03 19:41:41 ns3017362 sudo[6308]: pam_unix(sudo:session): session closed for user root
Feb 03 19:41:42 ns3017362 sudo[6313]: xxx : TTY=pts/0 ; PWD=/etc/nginx/sites-enabled ; USER=root ; COMMAND=/usr/bin/journalctl -xe
Feb 03 19:41:42 ns3017362 sudo[6313]: pam_unix(sudo:session): session opened for user root by xxx(uid=0)
我尝试了您给我的命令
nginx-T

/etc/nginx/sites-available$ sudo nginx -T

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
# configuration file /etc/nginx/nginx.conf:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

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

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

#mail {
#   # See sample authentication script at:
#   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
#   # 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;
#   }
#}

# configuration file /etc/nginx/modules-enabled/50-mod-http-auth-pam.conf:
load_module modules/ngx_http_auth_pam_module.so;

# configuration file /etc/nginx/modules-enabled/50-mod-http-dav-ext.conf:
load_module modules/ngx_http_dav_ext_module.so;

# configuration file /etc/nginx/modules-enabled/50-mod-http-echo.conf:
load_module modules/ngx_http_echo_module.so;

# configuration file /etc/nginx/modules-enabled/50-mod-http-geoip.conf:
load_module modules/ngx_http_geoip_module.so;

# configuration file /etc/nginx/modules-enabled/50-mod-http-image-filter.conf:
load_module modules/ngx_http_image_filter_module.so;

# configuration file /etc/nginx/modules-enabled/50-mod-http-subs-filter.conf:
load_module modules/ngx_http_subs_filter_module.so;

# configuration file /etc/nginx/modules-enabled/50-mod-http-upstream-fair.conf:
load_module modules/ngx_http_upstream_fair_module.so;

# configuration file /etc/nginx/modules-enabled/50-mod-http-xslt-filter.conf:
load_module modules/ngx_http_xslt_filter_module.so;

# configuration file /etc/nginx/modules-enabled/50-mod-mail.conf:
load_module modules/ngx_mail_module.so;

# configuration file /etc/nginx/modules-enabled/50-mod-stream.conf:
load_module modules/ngx_stream_module.so;

# configuration file /etc/nginx/mime.types:

types {
    text/html                             html htm shtml;
    text/css                              css;
    text/xml                              xml;
    image/gif                             gif;
    image/jpeg                            jpeg jpg;
    application/javascript                js;
    application/atom+xml                  atom;
    application/rss+xml                   rss;

    text/mathml                           mml;
    text/plain                            txt;
    text/vnd.sun.j2me.app-descriptor      jad;
    text/vnd.wap.wml                      wml;
    text/x-component                      htc;

    image/png                             png;
    image/tiff                            tif tiff;
    image/vnd.wap.wbmp                    wbmp;
    image/x-icon                          ico;
    image/x-jng                           jng;
    image/x-ms-bmp                        bmp;
    image/svg+xml                         svg svgz;
    image/webp                            webp;

    application/font-woff                 woff;
    application/java-archive              jar war ear;
    application/json                      json;
    application/mac-binhex40              hqx;
    application/msword                    doc;
    application/pdf                       pdf;
    application/postscript                ps eps ai;
    application/rtf                       rtf;
    application/vnd.apple.mpegurl         m3u8;
    application/vnd.ms-excel              xls;
    application/vnd.ms-fontobject         eot;
    application/vnd.ms-powerpoint         ppt;
    application/vnd.wap.wmlc              wmlc;
    application/vnd.google-earth.kml+xml  kml;
    application/vnd.google-earth.kmz      kmz;
    application/x-7z-compressed           7z;
    application/x-cocoa                   cco;
    application/x-java-archive-diff       jardiff;
    application/x-java-jnlp-file          jnlp;
    application/x-makeself                run;
    application/x-perl                    pl pm;
    application/x-pilot                   prc pdb;
    application/x-rar-compressed          rar;
    application/x-redhat-package-manager  rpm;
    application/x-sea                     sea;
    application/x-shockwave-flash         swf;
    application/x-stuffit                 sit;
    application/x-tcl                     tcl tk;
    application/x-x509-ca-cert            der pem crt;
    application/x-xpinstall               xpi;
    application/xhtml+xml                 xhtml;
    application/xspf+xml                  xspf;
    application/zip                       zip;

    application/octet-stream              bin exe dll;
    application/octet-stream              deb;
    application/octet-stream              dmg;
    application/octet-stream              iso img;
    application/octet-stream              msi msp msm;

    application/vnd.openxmlformats-officedocument.wordprocessingml.document    docx;
    application/vnd.openxmlformats-officedocument.spreadsheetml.sheet          xlsx;
    application/vnd.openxmlformats-officedocument.presentationml.presentation  pptx;

    audio/midi                            mid midi kar;
    audio/mpeg                            mp3;
    audio/ogg                             ogg;
    audio/x-m4a                           m4a;
    audio/x-realaudio                     ra;

    video/3gpp                            3gpp 3gp;
    video/mp2t                            ts;
    video/mp4                             mp4;
    video/mpeg                            mpeg mpg;
    video/quicktime                       mov;
    video/webm                            webm;
    video/x-flv                           flv;
    video/x-m4v                           m4v;
    video/x-mng                           mng;
    video/x-ms-asf                        asx asf;
    video/x-ms-wmv                        wmv;
    video/x-msvideo                       avi;
}

# configuration file /etc/nginx/sites-enabled/vhost2:
server {
        listen 8080;
        listen [::]:8080;

        server_name dev.xxx.fr;
        root /var/www/xxx/dev/web;
        index index.html index.php;

        location / {
                try_files $uri /index.php$is_args$args;
        }

        location ~ ^/index\.php(/|$) {
                fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
                fastcgi_split_path_info ^(.+\.php)(/.*)$;
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
                fastcgi_param DOCUMENT_ROOT $realpath_root;
                internal;
        }

        location ~ \.php$ {
                return 404;
        }

        error_log /var/log/nginx/dev-xxx_error.log;
        access_log /var/log/nginx/dev-xxx_access.log;
}

# configuration file /etc/nginx/fastcgi_params:

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REQUEST_SCHEME     $scheme;
fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

# configuration file /etc/nginx/sites-enabled/vhost1:
server {
        listen 8080;
        listen [::]:8080;

        server_name dev.yyy.fr;
        root /var/www/yyy/dev/public;
        index index.html index.php;

        location / {
                try_files $uri /index.php$is_args$args;
        }

        location ~ ^/index\.php(/|$) {
                fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
                fastcgi_split_path_info ^(.+\.php)(/.*)$;
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
                fastcgi_param DOCUMENT_ROOT $realpath_root;
                internal;
        }

        location ~ \.php$ {
                return 404;
        }

        error_log /var/log/nginx/dev-yyy_error.log;
        access_log /var/log/nginx/dev-yyy_access.log;
}
解决方案

我在端口80上终止进程,如下所示:

sudo lsof -i:80

COMMAND  PID     USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
nginx   9759     root   14u  IPv4 2001766      0t0  TCP *:http (LISTEN)
nginx   9759     root   15u  IPv6 2001767      0t0  TCP *:http (LISTEN)
nginx   9770 www-data   14u  IPv4 2001766      0t0  TCP *:http (LISTEN)
nginx   9770 www-data   15u  IPv6 2001767      0t0  TCP *:http (LISTEN)
nginx   9771 www-data   14u  IPv4 2001766      0t0  TCP *:http (LISTEN)
nginx   9771 www-data   15u  IPv6 2001767      0t0  TCP *:http (LISTEN)
nginx   9772 www-data   14u  IPv4 2001766      0t0  TCP *:http (LISTEN)
nginx   9772 www-data   15u  IPv6 2001767      0t0  TCP *:http (LISTEN)
nginx   9773 www-data   14u  IPv4 2001766      0t0  TCP *:http (LISTEN)
nginx   9773 www-data   15u  IPv6 2001767      0t0  TCP *:http (LISTEN)
nginx   9774 www-data   14u  IPv4 2001766      0t0  TCP *:http (LISTEN)
nginx   9774 www-data   15u  IPv6 2001767      0t0  TCP *:http (LISTEN)
nginx   9775 www-data   14u  IPv4 2001766      0t0  TCP *:http (LISTEN)
nginx   9775 www-data   15u  IPv6 2001767      0t0  TCP *:http (LISTEN)
nginx   9776 www-data   14u  IPv4 2001766      0t0  TCP *:http (LISTEN)
nginx   9776 www-data   15u  IPv6 2001767      0t0  TCP *:http (LISTEN)
nginx   9777 www-data   14u  IPv4 2001766      0t0  TCP *:http (LISTEN)
nginx   9777 www-data   15u  IPv6 2001767      0t0  TCP *:http (LISTEN)
然后我更新所有vhost以使用端口80并重新启动nginx。它工作正常


感谢大家的帮助和提示(命令):。

nginx是否重定向,或者这正是您看到的?例如,
curl-I是什么http://dev.xxx.fr
show?或者没有
-I
选项的curl?1/您删除了默认的vhost符号链接,2/重新启动了nginx,3/仍然可以看到原始站点,这是否正确?您应该能够运行
lsof-I:80
(可能以root用户身份)来确定端口80的用途。使用
nginx-T
(大写
T
)查看Nginx实际正在阅读的配置。我更新了我的帖子,介绍了您向我建议的每一点;)。