我需要帮助才能在两个网址上运行相同的localhost页面。
我在配置的localhost上运行nginx,以便我的项目网址如下所示:http://project.loc
。我需要它现在正常工作,而且必须在localhost/project.loc
或127.0.0.1/project.loc
上运行,而不需要重定向。这样的事可能吗?我已经开始工作了,所以当我转到localhost/project.loc
时,它会将我重定向到http://project.loc
。这是我的服务器配置:
server {
listen 80;
server_name localhost;
location ~ ^/(?<project>[^/]+)(?<rest>.*) {
resolver 127.0.0.1;
proxy_pass http://$project$rest;
}
}
server {
# fix for ERR_INCOMPLETE_CHUNKED_ENCODING
sendfile off;
listen 80;
client_max_body_size 700M;
server_name ~^(.*?([^.]*)?\.?([^.]*)\.loc)$;
set $server_root /Users/username/Development/php;
if (-e $server_root/$2.loc) {
set $domain $2.loc;
}
if (-e $server_root/$2.loc) {
set $domain $2.loc;
}
if (-e $server_root/$2.$3.loc) {
set $domain $2.$3.loc;
}
if (-e $server_root/$1) {
set $domain $1;
}
if (-e $server_root/$domain/web) {
set $root $server_root/$domain/web;
}
if (-e $server_root/$domain/www) {
set $root $server_root/$domain/www;
}
if (-e $server_root/$domain/public) {
set $root $server_root/$domain/public;
}
if (-e $server_root/$domain/web/www) {
set $root $server_root/$domain/web/www;
}
root $root;
index index.html index.htm index.php index.cgi index.pl index.xhtml;
error_log /usr/local/var/log/nginx.log;
access_log on;
location ~ \.php$ {
try_files $uri = 404;
include /usr/local/etc/nginx/fastcgi_params;
fastcgi_pass unix:/tmp/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
fastcgi_connect_timeout 1800;
fastcgi_send_timeout 1800;
fastcgi_read_timeout 1800;
fastcgi_buffer_size 512k;
fastcgi_buffers 8 512k;
fastcgi_busy_buffers_size 1024k;
fastcgi_temp_file_write_size 512k;
}
location / {
try_files $uri $uri/ /index.php?$args;
autoindex on;
}
}