【问题标题】:Redirecting with nginx redirects to localhost in Windows使用 nginx 重定向重定向到 Windows 中的 localhost
【发布时间】:2015-10-18 13:20:06
【问题描述】:

我正在尝试通过 nginx 通过其配置文件和启用站点的文件夹中的文件将我的 dns 重定向到 ip, 但它总是重定向到显示“欢迎使用 nginx!”的 nginx 主页。

我的配置文件包括:

NGINX.CONF

 user  www-data www-data;
    worker_processes  4;

    #error_log  logs/error.log;
    #error_log  logs/error.log  notice;
    #error_log  logs/error.log  info;

    pid        var/run/nginx.pid;


    events {
        worker_connections  1024;
    }


    http {
        include       mime.types;
        default_type  application/octet-stream;
        include /conf/*.conf;
        include /conf/sites-enabled/*;

    #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  logs/access.log  main;

    sendfile        on;
    tcp_nopush     on;
    tcp_nodelay    on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    types_hash_max_size 2048;
    gzip  on;
    gzip_disable    "msie6";

    server {
        listen       80;
        server_name  fe.paytm.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {`enter code here`
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
    }

启用站点的文件夹中的 conf 文件

 server {  
     server_name   my.domain.com; 
      root C:/Users/some/absolute-path/public;
      index index.html index.htm; 

     access_log /var/log/nginx/my-domain.access.log; 
      error_log  /var/log/nginx/my-domain.error.log; 
      underscores_in_headers on; 
      location /   {  
         root C:/Users/some/absolute-path/public;      
         proxy_pass http://localhost:8997;
      }
    }

ip的host入口也完成了:

 127.0.0.1  my.domain.com

我错过了什么或做错了什么

【问题讨论】:

    标签: windows apache redirect nginx


    【解决方案1】:

    您忘记在配置中添加listen 80。由于 nginx 正在使用 default.conf 并显示“欢迎使用 nginx!”
    更新后的配置如下所示:

    server {  
      listen 80;
      server_name   my.domain.com; 
      root C:/Users/some/absolute-path/public;
      index index.html index.htm; 
    
      access_log /var/log/nginx/my-domain.access.log; 
      error_log  /var/log/nginx/my-domain.error.log; 
      underscores_in_headers on; 
      location /   {  
         root C:/Users/some/absolute-path/public;      
         proxy_pass http://localhost:8997;
      }
    }
    

    【讨论】:

    • 现在它不再显示主页,而是开始出现“找不到页面”错误.....下一步可以做什么..
    • 是的,这意味着现在 nginx 正在使用上述配置检测请求并提供服务。很可能它可能无法找到 access_log/error_log 路径,因为它们是基于 linux 和 root Windows 的。请根据您的要求修复它们,它应该可以正常工作。如果仍然有问题,请发表评论(路径更改为基于 Windows 后)
    猜你喜欢
    • 2020-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-20
    • 2021-12-16
    • 2013-01-08
    • 2016-01-21
    相关资源
    最近更新 更多