我有两个应用程序运行在端口8000 (本地)和react 3000(本地)上的ASW Symfony上,但是通过端口80的TCP访问重定向是通过侦听nginx服务器中的端口80来实现的。
server {
listen 80;
server_name example.info www.example.info;
location / {
proxy_pass http://127.0.0.1:3000;
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;
proxy_redirect off;
}
}
server {
listen 8000;
server_name example.info www.example.info;
location / {
proxy_pass http://127.0.0.1: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;
proxy_redirect off;
}
}
我试着监听和重定向两个端口,但都没有成功。在服务器内部,Symfony应用程序可以从外部使用curl http://127.0.0.1:8000访问,我正在向asw.external.ip发送api请求(123.123.123.123:800),但我会超时。我怎么能从外面进入我的后端呢?
发布于 2018-03-31 21:10:01
AWS ElasticBeanstalk -将代理服务器配置到后端
您也可以将此配置文件用于Aws Ec2。
/etc/nginx/con.d/proxy.conf
upstream nodejs {
server 127.0.0.1:5000;
keepalive 256;
}
server {
listen 8080;
access_log /var/log/nginx/access.log main;
location / {
proxy_pass http://nodejs;
proxy_set_header Connection "";
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
gzip on;
gzip_comp_level 4;
gzip_types text/html text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
## Optional configuration if you want to allow AWS
## to cache your static files
location /static {
alias /var/app/current/static;
}
}
编辑-为Symfony配置Nginx
server {
listen 8080;
server_name sf2testproject.dev;
root /home/maurits/public_html/web;
location / {
# try to serve file directly, fallback to rewrite
try_files $uri @rewriteapp;
}
location @rewriteapp {
# rewrite all to app.php
rewrite ^(.*)$ /app.php/$1 last;
}
location ~ ^/(app|app_dev|config)\.php(/|$) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
}
其中:
listen
是您的应用程序与世界通信的端口。fastcgi_pass
是一种二进制协议,用于将交互式程序与web服务器连接起来。参考文献:
https://stackoverflow.com/questions/49586717
复制相似问题