Php NGINX访问多个站点相同的IP url
我想知道如何在Nginx上拥有多个站点,并能够使用相同的IP访问每个站点(没有域,因为我在本地实验室进行测试) 我将服务器放在一台单独的PC上,并使用IP从我的计算机远程访问它。两者都在同一局域网上 在目录/var/www/I中有两个站点“nextcloud”和“phpmyadmin”。我希望能够通过放置(例如)192.168.1.14/nextcloud和192.168.1.14/phpmyadmin来输入这两个。或者在www目录中有任何其他项目 我尝试了我找到的所有解决方案,但没有一个对我有效。例如,当我输入phpmyadmin时,它让我下载页面而不是输入页面 在启用的/etc/nginx/sites中,我有两个文件,一个来自nextcloud:Php NGINX访问多个站点相同的IP url,php,nginx,phpmyadmin,Php,Nginx,Phpmyadmin,我想知道如何在Nginx上拥有多个站点,并能够使用相同的IP访问每个站点(没有域,因为我在本地实验室进行测试) 我将服务器放在一台单独的PC上,并使用IP从我的计算机远程访问它。两者都在同一局域网上 在目录/var/www/I中有两个站点“nextcloud”和“phpmyadmin”。我希望能够通过放置(例如)192.168.1.14/nextcloud和192.168.1.14/phpmyadmin来输入这两个。或者在www目录中有任何其他项目 我尝试了我找到的所有解决方案,但没有一个对我有
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/nextcloud/;
index index.php index.html index.htm;
server_name localhost;
client_max_body_size 512M;
fastcgi_buffers 64 4K;
location / {
root /var/www/nextcloud;
rewrite ^ /index.php$request_uri;
}
location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
deny all;
}
location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
deny all;
}
location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+)\.php(?:$|/) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_intercept_errors on;
fastcgi_request_buffering off;
}
location ~ ^/(?:updater|ocs-provider)(?:$|/) {
try_files $uri/ =404;
index index.php;
}
location ~ \.(?:css|js|woff|svg|gif)$ {
try_files $uri /index.php$request_uri;
add_header Cache-Control "public, max-age=15778463";
access_log off;
}
location ~ \.(?:png|html|ttf|ico|jpg|jpeg)$ {
try_files $uri /index.php$request_uri;
# Optional: Don't log access to other assets
access_log off;
}
}
以及phpmyadmin的:
server {
listen 80;
listen [::]:80;
root /var/www/phpmyadmin/;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name localhost;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
}
尝试在/var/www/(test1和test2)中创建两个测试文件夹,每个文件夹中都有一个index.html文件,并修改nginx默认文件,但这对我也不起作用
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name localhost;
index index.html;
location / {
return 410; # Default root of site won't exist.
}
location /test1/ {
alias /var/www/test1/;
try_files $uri $uri/ =404;
# any additional configuration for non-static content
}
location /test2/ {
alias /var/www/test2/;
try_files $uri $uri/ =404;
# any additional configuration for non-static content
}
}
正如我所说,我尝试了不同的解决方案。我遇到的另一个问题是,它只将我重定向到nextcloud,尽管我将phpmyadmin放在url中。前面我已经提到过,当我进入时,下载index.php。多谢各位
对不起,我的英语不好。简单地将nextcloud.my和phpmyadmin.my添加到您的
.hosts
文件中,并在Nginx中侦听域名。
您建议的选项也可以使用,但它充满了bug,在传输到工作服务器的过程中可能会出现困难。简单地将nextcloud.my和phpmyadmin.my添加到您的
.hosts
文件中,并在Nginx中侦听域名。
您建议的选项也可以工作,但它充满了bug,在传输到工作服务器的过程中可能会出现困难