【问题标题】:How to get acess to web-app via IP or localhost in NGINX?如何在 NGINX 中通过 IP 或 localhost 访问 web-app?
【发布时间】:2016-06-25 01:22:30
【问题描述】:

我的localhost 上有一个Codeigniter 应用程序。我这样配置主机文件:

   127.0.0.1       localhost
   127.0.0.1       myapp

所以我可以用链接打开我的项目 http://myapp/ 但是当我尝试通过http://localhost/myapphttp://192.168.1.10/myapp 打开项目时,它不起作用。但是使用 apache 一切正常。我想在 nginx 上解决这个问题。

我的 nginx 配置:

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

   root /var/www/nginx/myapp;
   index index.html index.htm index.php;

   server_name myapp www.myapp;

        location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
                expires max;
                log_not_found off;
        }

        location / {
                # Check if a file or directory index file exists, else route it to index.php.
                try_files $uri $uri/ /index.php;
        }


    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }
}

【问题讨论】:

    标签: php codeigniter nginx server localhost


    【解决方案1】:

    服务器块必须是默认服务器或在server_name指令中命名。

    要使服务器阻止默认服务器,请使用:

    listen 80 default_server;
    listen [::]:80 default_server;
    

    或扩展您的 server_name 指令以包含所有名称:

    server_name myapp www.myapp localhost 192.168.1.10;
    

    详情请见this document

    【讨论】:

    • 谢谢,但之后 - 任何 ajax 请求都从服务器返回 404 错误,而不是来自 CI 错误管理器。我认为没有任何跨域请求。
    猜你喜欢
    • 2016-11-05
    • 2011-07-17
    • 2015-11-30
    • 2022-11-02
    • 1970-01-01
    • 1970-01-01
    • 2021-12-16
    • 2018-09-28
    • 2021-01-08
    相关资源
    最近更新 更多