上下文是我在端口9001上运行了一个webapp,但是想让app.company.com
指向我的应用程序。我不确定这是否重要,但我可以采取两种方法。
server.company.com:9001
哪条路线更好,为什么重要?
你的问题有点广泛,但一般来说,如果你使用的是nginx,你的应用程序可能会有一些静态内容,如css,js,fonts等,你希望nginx能够提供那些服务。静态内容,只有你的应用程序(即在端口9001运行的应用程序)来处理动态内容,考虑到这一点,你可以做的是让nginx在端口80监听,并将动态内容传递给端口9001。
例:
server {
listen 80 default_server;
listen [::]:80;
root /var/www/html;
server_name example.com;
location /static {
alias /var/www/html/static;
}
location / {
try_files $uri @backend;
}
location @backend {
proxy_pass http://server.company.com:9001;
# other configuration settings here
}
# other location configuration here
}