nginx - 如何使用 nginx 将域代理到另一个域?
问题描述
我尝试使用 nginx 部署 laravel,所以我编写了 ngix.conf,如下所示,它对我来说很好用。
server {
listen 8000 default_server;
listen [::]:8000 default_server;
root /home/back-stage/public;
index index.php index.html index.htm;
server_name _;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass 127.0.0.1:9999;
fastcgi_index index.php;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fixes timeouts
fastcgi_read_timeout 600;
include fastcgi_params;
}
}
但是如果我想代理 127.0.1:3000 到 127.0.1:8000 呢?
我只是像下面这样重写了 nginx.conf,但它失败了。如何解决?
server {
listen 3000 default_server;
listen [::]:3000 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
proxy_pass http://localhost:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
server {
listen 8000 default_server;
listen [::]:8000 default_server;
root /home/back-stage/public;
index index.php index.html index.htm;
server_name _;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass 127.0.0.1:9999;
fastcgi_index index.php;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fixes timeouts
fastcgi_read_timeout 600;
include fastcgi_params;
}
}
解决方案
推荐阅读
- java - 通过二维数组存储一个数的素数
- ios - 如果点击后退按钮,导航栏标题颜色不会改变
- javascript - 使用 javascript 生成请求名称时 Flask 中的错误请求错误
- c++ - 对我的 C++ 金字塔作业进行小调整?我该怎么做?
- android - 如何在android中实现守卫和拦截器
- sql - 如何在不同的数据库中查找表列?
- r - 使用 mutate 和 case_when 在 dplyr 中通过双重条件重新编码变量
- sql - 使用每行计算值的 where 子句进行大规模更新?
- linux - 使用 sed 解析 nmap -oG 输出
- memory - Rust 线程之间的内存共享