0

I have a new dedicated server with centos 7. For the testing purpose i need to use nginx on a temporary url like 127.0.0.1/~linux but the issue remains how should i post the nginx to this host(server_name). I unable to create a 127.0.0.1/~linux.conf file for nginx configuration. Sounds weird but i need to get a magento2 installation work on this CentOS 7 dedicated server. The magento2 requires nginx.

So thereby, i am in a deadlock state now. Please help me overcome this issue.

Tombart
  • 2,143
  • 3
  • 27
  • 48
Mek
  • 1
  • 1
    Why are you trying to do this? – Michael Hampton Mar 19 '17 at 20:51
  • 1
    This is fairly trivial. You just create a configuration file (probably with a name like localhost.conf), create a server block, and if it's the only listener set is as the default (default_server directive). Give this a go, if it doesn't work ask a question including the configuration, error messages, logs, and behaviour. – Tim Mar 19 '17 at 21:05
  • Well i am a developer, dont have any experience of server administration. My application(magento) requires nginx installation. Can we run nginx without the configuration. For testing purpose i need to run nginx on temp url 103.**5.**.191/~mage. I hope there is a workaround, can you please help me with the config file. – Mek Mar 20 '17 at 05:37

1 Answers1

1

Just place a configuration file in e.g. /etc/nginx/conf.d/site.conf with following content:

server {
        listen 80;
        root /usr/share/nginx/html;
        server_name _;

        location / {
                try_files $uri $uri/ =404;
        }
}

now create a directory with your desired name, and add some content:

mkdir -p /usr/share/nginx/html/~linux
echo "hello world" > /usr/share/nginx/html/~linux/test
chown -R nginx:nginx /usr/share/nginx/html/

test & reload nginx:

nginx -t && service nginx reload

now your content should be available:

curl localhost:80/~linux/test
hello world

You could do some advanced URI matching in location block, but based on the information you've provided it would be unnecessary overkill.

Tombart
  • 2,143
  • 3
  • 27
  • 48