简体   繁体   中英

How to get acess to web-app via IP or localhost in NGINX?

I have a Codeigniter application on my localhost . I configured hosts file like this:

   127.0.0.1       localhost
   127.0.0.1       myapp

So I can open my project with link http://myapp/ But when I try open project via http://localhost/myapp or http://192.168.1.10/myapp it's not working. But with apache all is ok. I'd like to solve this problem on nginx.

My nginx config:

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

Either the server block must be the default server or named in the server_name directive.

To make the server block the default server use:

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

Or extend your server_name directive to include all the names:

server_name myapp www.myapp localhost 192.168.1.10;

See this document for details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM