server {
server_name example.com;
location / {
# assuming apache is on port 81 for example
proxy_pass http://127.0.0.1:81;
# to make apache detect the host header
proxy_set_header Host $host;
}
# if you have assets folders, you can let nginx serve them directly,
# instead of passing them to apache
location /images { # or /css or /js .. etc
try_files $uri =404;
}
}
注意:在资产的情况下,有时某些站点通过重写来提供资产,甚至由应用程序自己处理,您可以通过将其添加到资产位置作为后备将其传递给 apache,如下所示
location /images {
try_files $uri @apache;
}
location @apache {
proxy_pass http://127.0.0.1:81;
}
在 apache 中,您创建一个虚拟主机
<VirtualHost *:81>
ServerName example.com
# the rest of the config if needed
</VirtualHost>