作为程序员,我试着走出我的舒适区,试着从一个web服务器上为自己做一个完整的设置。我可以用apache来做,但是,我需要使用proxy\u pass,因为我有一些golangapi。做了一些研究,我意识到如果我也为Symfony应用程序设置一个代理,我可以得到更好的基准测试:
但是,要运行这个symfony应用程序,我需要使用一个子目录。到目前为止,我设法通过ngnix上的代理传递运行golang和symfony,但是symfony没有重写路由:
http://myip/MYSUBDIR/app_dev.php/myroute
所有(后台)加载的url(用于文件、脚本、ajax请求等)如下
http://myip/app_dev.php/myroute
如何重写url来解决我的问题???
我正在vps、php fpm 7.3和nginx/1.14.0(Ubuntu)上运行Ubuntu18.04
Symfony在v3.4上
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
}
location /MYSUBDIR/ {
proxy_pass http://127.0.0.1:8080/;
proxy_cache mysubdir_cache_setup;
proxy_cache_key "$scheme://$host$request_uri";
proxy_cache_lock on;
proxy_cache_use_stale updating error timeout http_500 http_502 http_503 http_504;
add_header X-Cache $upstream_cache_status;
error_log /var/log/nginx/mysubdir_cache_error.log;
access_log /var/log/nginx/mysubdir_cache_access.log;
}
location /phpmyadmin {
index index.php index.html index.htm;
root /usr/share;
}
location /goapi/ {
proxy_pass http://127.0.0.1:9003/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_cache_bypass $http_upgrade;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
location ~ /\.ht {
deny all;
}
}
和#/etc/nginx/sites available/mysubdir
server {
listen 8080;
server_name localhost 127.0.0.1;
root /var/www/html/mysubdir/web;
location / {
# try to serve file directly, fallback to app.php
try_files $uri /app.php$is_args$args;
}
# DEV
# This rule should only be placed on your development environment
# In production, don't include this and don't deploy app_dev.php or config.php
location ~ ^/(app_dev|config)\.php(/|$) {
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
# When you are using symlinks to link the document root to the
# current version of your application, you should pass the real
# application path instead of the path to the symlink to PHP
# FPM.
# Otherwise, PHP's OPcache may not properly detect changes to
# your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
# for more information).
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}
# PROD
location ~ ^/app\.php(/|$) {
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
# When you are using symlinks to link the document root to the
# current version of your application, you should pass the real
# application path instead of the path to the symlink to PHP
# FPM.
# Otherwise, PHP's OPcache may not properly detect changes to
# your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
# for more information).
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
# Prevents URIs that include the front controller. This will 404:
# http://domain.tld/app.php/some-path
# Remove the internal directive to allow URIs like this
internal;
}
# return 404 for all other php files not matching the front controller
# this prevents access to other php files you don't want to be accessible.
location ~ \.php$ {
return 404;
}
error_log /var/log/nginx/mysubdr_error.log;
access_log /var/log/nginx/mysubdr_access.log;
}
phpmydmin和goapi位置工作正常
拜托,我怎么解决这件事?!