I
I
ironheaddd2019-06-07 13:21:46
Nginx
ironheaddd, 2019-06-07 13:21:46

Nginx: site from internet and site from LAN?

There is a Debian 9 server with nginx + php-fpm on it.
Site config for access from the Internet:

user.site.com

server {
listen 80 default_server;
server_name user.site.com www.user.site.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
ssl_certificate /home/back/ssl-key/mycert.crt;
ssl_certificate_key /home/back/ssl-key/device.key;
root /home/back/user.site/public;
index index.php;
access_log /var/log/nginx/site-access.log;
error_log /var/log/nginx/site-error.log;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}

Config for access from inside:
admin.site.com

server {
listen 80;
server_name admin.site.com www.admin.site.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
ssl_certificate /home/back/ssl-key/mysert.crt;
ssl_certificate_key /home/back/ssl-key/device.key;
root /home/back/admin.site/public;
index index.php;
access_log /var/log/nginx/site-access.log;
error_log /var/log/nginx/site-error.log;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}

The user.site.com site works, but in order to access the admin.site.com site, you need to edit the hosts file and add:
hosts

local_ip_addr admin.site.com

Actually, the question is: is it possible to configure nginx in such a way as to avoid editing the hosts file?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question