Answer the question
In order to leave comments, you need to log in
How to make proxy_pass on React Nginx app?
Launched a React app on port 3006
Doing proxying
location /crm/ {
rewrite ^/crm/(.*)$ /$1 break;
proxy_pass http://127.0.0.1:3006/;
}
sub_filter 'src="/' 'src="/crm/';
sub_filter_once off;
gzip
is in modeoff
gzip off;
gzip_comp_level 5;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
http://my.site:3006
the application it works https://my.site/crm
the application it doesn't work server {
listen 443 ssl;
server_name my.site www.my.site;
root /var/www/html/;
index index.html;
ssl_certificate /var/www/html/ssl/ssl-bundle-21.crt;
ssl_certificate_key /var/www/html/ssl/HSSL-123456789p4cc9.key;
gzip off;
gzip_comp_level 5;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
if ($allowed_country = no) {
return 403;
}
location ~ ^/api {
client_max_body_size 50M;
try_files $uri /api/public/index.php;
index index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php8.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
include fastcgi_params;
}
}
location ~ ^/files {
try_files $uri /api/public$request_uri;
}
location ~ /crm/ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://127.0.0.1:3006;
}
location / {
proxy_pass http://127.0.0.1:5000;
}
}
server {
listen 80;
server_name my.site www.my.site;
if ($allowed_country = no) {
return 403;
}
location / {
return 301 https://$host$request_uri;
}
}
Answer the question
In order to leave comments, you need to log in
The construct rewrite ^/crm/(.*)$ /$1 break;
removes /crm/ from the URI
This is how it will be proxied:
location ~ /crm/ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://127.0.0.1:3006;
}
GET /crm/test.css HTTP/1.0
Host: example.com
X-Real-IP: 192.168.254.254
X-Forwarded-For: 192.168.254.254
X-Forwarded-Proto: https
Connection: close
user-agent: curl/7.68.0
accept: */*
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question