具有不同端口和子域的资产文件的 Nginx 配置
Nginx configuration for assets files with different port and subdomain
我想用 nginx 提供我的资产文件。 ngnix 服务器侦听端口,例如 8000(它必须不同于 80),我想通过 assets.mydomain.com 这样的子域访问文件。
我尝试配置,但我做不到。我应该如何配置?谢谢你的回答。
server {
listen 8000;
server_name localhost;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
}
# another virtual host using mix of IP-, name-, and port-based configuration
server {
listen 8000;
server_name assets.localhost;
location /assets/ {
root /var/www/html/skytrip/assets
try_files $uri $uri/ =404;
}
}
一般来说,您应该更具体地说明您遇到的问题。您期望该配置有什么行为?到底发生了什么?有错误吗?您可以发送日志文件的最后几行吗?等等
你忘了根指令后面的分号吗?
我想用 nginx 提供我的资产文件。 ngnix 服务器侦听端口,例如 8000(它必须不同于 80),我想通过 assets.mydomain.com 这样的子域访问文件。
我尝试配置,但我做不到。我应该如何配置?谢谢你的回答。
server {
listen 8000;
server_name localhost;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
}
# another virtual host using mix of IP-, name-, and port-based configuration
server {
listen 8000;
server_name assets.localhost;
location /assets/ {
root /var/www/html/skytrip/assets
try_files $uri $uri/ =404;
}
}
一般来说,您应该更具体地说明您遇到的问题。您期望该配置有什么行为?到底发生了什么?有错误吗?您可以发送日志文件的最后几行吗?等等
你忘了根指令后面的分号吗?