Nginx虚拟主机?

时间:2014-09-17 23:44:54

标签: nginx virtualhost vhosts

我有一台计算机正在运行,试图运行nginx。我的主网站上有两个CName子域名,并且我已经相应地设置了我的配置文件,但是当我尝试连接它时,我得到一个大的"无法连接到服务器"错误。我对路由器进行了三重检查,端口80打开了。此外,我的plex服务器工作正常。我如何找出问题所在,以便我可以解决它?

我的第一个想法是,它可能与权限有关?我将文件存储在两个单独的主目录中。我需要设置哪些权限,以便nginx可以访问它们以及用户?

server {
    listen 80; 
    server_name server.----.com;
    root /home/admin/public_html;
    index index.html index.htm;
}

server {
    listen 80; 
    server_name minecraft.----.com;
    root /home/minecraft/public_html;
    index index.html index.htm;
}

/ var / log / nginx中的所有内容都是空白

curl 127.0.0.1获取curl: (7) Failed to connect to 127.0.0.1 port 80: Connection refused

nginx -V获得:

nginx version: nginx/1.6.1 TLS SNI support enabled configure arguments: --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_spdy_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module --add-module=/build/buildd/nginx-1.6.1/debian/modules/nginx-auth-pam --add-module=/build/buildd/nginx-1.6.1/debian/modules/nginx-dav-ext-module --add-module=/build/buildd/nginx-1.6.1/debian/modules/nginx-echo --add-module=/build/buildd/nginx-1.6.1/debian/modules/nginx-upstream-fair --add-module=/build/buildd/nginx-1.6.1/debian/modules/ngx_http_substitutions_filter_module

输出" sudo nginx -t /etc/nginx/nginx.conf":nginx: invalid option: "/etc/nginx/nginx.conf"

输出" sudo netstat -pant | grep LISTEN":

tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1511/cupsd
tcp 0 0 0.0.0.0:39423 0.0.0.0:* LISTEN 1501/Plex Plug-in [ tcp 0 0 0.0.0.0:1224 0.0.0.0:* LISTEN 1627/Plex DLNA Serv tcp 0 0 0.0.0.0:52718 0.0.0.0:* LISTEN 1757/Plex Plug-in [ tcp 0 0 0.0.0.0:6000 0.0.0.0:* LISTEN 1309/X
tcp 0 0 0.0.0.0:32469 0.0.0.0:* LISTEN 1627/Plex DLNA Serv tcp 0 0 127.0.1.1:53 0.0.0.0:* LISTEN 1143/dnsmasq
tcp 0 0 0.0.0.0:43094 0.0.0.0:* LISTEN 1671/Plex Plug-in [ tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 964/sshd
tcp6 0 0 ::1:631 :::* LISTEN 1511/cupsd
tcp6 0 0 :::25565 :::* LISTEN 1495/java
tcp6 0 0 :::32400 :::* LISTEN 1282/Plex Media Ser tcp6 0 0 :::6000 :::* LISTEN 1309/X
tcp6 0 0 :::32401 :::* LISTEN 1282/Plex Media Ser tcp6 0 0 :::22 :::* LISTEN 964/sshd

输出" ps -ef | grep nginx":

root 4014 1 0 15:03 ? 00:00:00 nginx: master process nginx www-data 4015 4014 0 15:03 ? 00:00:00 nginx: worker process www-data 4016 4014 0 15:03 ? 00:00:00 nginx: worker process www-data 4017 4014 0 15:03 ? 00:00:00 nginx: worker process www-data 4018 4014 0 15:03 ? 00:00:00 nginx: worker process root 24441 1 0 14:07 ? 00:00:00 nginx: master process nginx www-data 24442 24441 0 14:07 ? 00:00:00 nginx: worker process www-data 24443 24441 0 14:07 ? 00:00:00 nginx: worker process www-data 24444 24441 0 14:07 ? 00:00:00 nginx: worker process www-data 24445 24441 0 14:07 ? 00:00:00 nginx: worker process admin 29159 28078 0 19:44 pts/1 00:00:00 grep --color=auto nginx

输出" telnet 127.0.0.1 80":

Trying 127.0.0.1... telnet: Unable to connect to remote host: Connection refused

/etc/nginx/nginx.conf:

user www-data;
worker_processes 4;
pid /run/nginx.pid;

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;

    ##
    # Logging Settings
    ##

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

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

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

    ##
    # nginx-naxsi config
    ##
    # Uncomment it if you installed nginx-naxsi
    ##

    #include /etc/nginx/naxsi_core.rules;

    ##
    # nginx-passenger config
    ##
    # Uncomment it if you installed nginx-passenger
    ##

    #passenger_root /usr;
    #passenger_ruby /usr/bin/ruby;

    ##
    # Virtual Host Configs
    ##

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

2 个答案:

答案 0 :(得分:0)

检查nginx服务状态,如果您为此计算机使用防火墙,则检查防火墙。

答案 1 :(得分:0)

你能先解决这个错误吗?

nginx: invalid option: "/etc/nginx/nginx.conf"

可能是某些行未正确结束;