将nginx中的端口号映射到自定义主机名

问题描述 投票:1回答:1

我在浏览器中启动了点http://localhost:8080到我的开发PHP应用程序时有一个Docker实例。我想修改下面的nginx配置,使我能够在浏览器中使用像backend.docker这样的自定义主机名,而不是使用localhost:8080 - 他们通过nginx这样做的方法是什么?

server {

# Set the port to listen on and the server name
listen 80 default_server;

# Set the document root of the project
root /var/www/public;

# Set the directory index files
index index.php;

# Specify the default character set
charset utf-8;

# Setup the default location configuration
location / {
    try_files $uri $uri/ /index.php;
}

# Specify the details of favicon.ico
location = /favicon.ico { access_log off; log_not_found off; }

# Specify the details of robots.txt
location = /robots.txt  { access_log off; log_not_found off; }

# Specify the logging configuration
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

sendfile off;

client_max_body_size 100m;

# Specify what happens when PHP files are requested
location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass php:9000;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param APPLICATION_ENV development;
    fastcgi_intercept_errors off;
    fastcgi_buffer_size 16k;
    fastcgi_buffers 4 16k;
}

# Specify what happens what .ht files are requested
location ~ /\.ht {
    deny all;
 }
}
docker nginx hostname nginx-reverse-proxy
1个回答
0
投票

您的主机将8080指向Docker的80.您可以在主机中创建自定义主机名,即backend.docker,但是对于端口,您需要设置反向代理,除非它在Docker中主机为80。

© www.soinside.com 2019 - 2024. All rights reserved.